Posted by Willy on April 20, 2007
In Reply to Re: Tabs and OnChange events posted by Jay on
April 19, 2007
: : Hide Form1 and show Form2 when the second tab is clicked on the "TabControl" component
of Form1?
: : And the reverse, hide Form2 and show Form1 when the first tab is clicked on Form2?
: : If that's
what you mean, let me know and I'll test a few code lines. BTW, nice idea to switch from one Delphi
form to another, haven't considered it yet :)
: Yep that's exactly what I mean. I haven't been able
to fathom it yet, good luck!
If you have two forms, each with a Delphi TabControl component, each with the same two Tabs-strings (e.g. "Analysis" and "Results"):
1. Let the forms know each other.
Add a line to the unit of Form1, immediately after the line "implementation":
uses Unit2;
...and add a line to the unit of Form2, immediately after the line "implementation":
uses Unit1;
2. Add an OnChange event handler for the TabControl of Form1:
procedure TForm1.TabControl1Change(Sender: TObject); begin if TabControl1.TabIndex = 1 then begin Hide; Form2.Show; Form2.TabControl1.TabIndex := 1; end; end;
3. Add an OnChange event handler to Form2:
procedure TForm2.TabControl1Change(Sender: TObject); begin if TabControl1.TabIndex = 0 then begin Hide; Form1.Show; Form1.TabControl1.TabIndex := 0; end; end;
Cheers,
Willy
Related articles
Follow Ups