How to execute some code when user switches to a nested tabsheet?
I have a TPageCOntrol which has 3 TTabSheet and some of those have further TPageCOntrol which have a TTabSheet
Sort of
Page Control 1
TabSheet 1
TabSheet 2
Page Control 2
TabSheet 2a
TabShee开发者_开发技巧t 2b
TabSheet 3
Now, whenever one of those tabsheets becomes visible to the user I want to execute some code, but I'm not sure which event to hook.
For instance, if the user is looking at TabSheet 1
and switches to TabSheet 2
where TabSheet 2a
is showing, then I want to execute Tabsheet 2a's code, but I can't hook TabSheet 2a's OnEnter or OnShow. And it isn't Page Control2's OnChange.
In fact, all that I can see is to put a whole bunch of switch/case into Page Control 1's OnChange event ... is tehre a better way?
each TabSheet has the "OnShow" event which is triggered whenever a user clicks on it and makes it visible, this should do the trick, however having a pagecontrol inside a tabsheet which has another pagecontrol as parent and so on it's pretty heavy on the UI, try using frames which you will create on tabsheet's OnShow event and destroy on tabsheet's OnHide event.
Edit: if you choose to use TFrames inside a tabsheet, go to the "public" section of the frame, press CTRL+SPACE and type "create" so that you will override the "Create" constructor and repeat for "Destroy" so you will override that aswell
I hooked each PageControl's OnChange() and checked ActivePage. It works for me, without redesigning to use frames.
I stricktly use the "onEnter" Event on the Tabsheets. but i they are only fired, when the focus get "into" the tabsheet. so i have manually set the focus into the tabsheet when the pagecontrol changes.
procedure TForm1.PageControl1Change(Sender: TObject);
begin
pagecontrol1.ActivePage.SetFocus;
end
精彩评论