switch between frames

I have to keep switching between many Frames.
(Outlook style sidebar/application)
What is the best way to hide/show a frame on button click ?
I use form as parent i.e..
Frame2.Parent := Form1;
Frame2.Align := alClient;
Frame2.show;
LVL 22
senadAsked:
Who is Participating?
 
TheRealLokiConnect With a Mentor Senior DeveloperCommented:
There are several ways to do what you want
Firstly, if your frame tkes up the entire control(form1 for instance) then
you can hide the other frame(s) and show your desired one
procedure TForm1.bShowFrame1Click(Sender: TObject);
begin
  Frame2.Hide;
  Frame1.Show;
end;

procedure TForm1.bShowFrame2Click(Sender: TObject);
begin
  Frame1.Hide;
  Frame2.Show;
end;

Secondly, If you are not using align (alClient) then you could show all the frames, and simply bring the desired one to the foreground
procedure TForm1.bFrame1InFrontClick(Sender: TObject);
begin
  Frame1.BringToFront;
end;

procedure TForm1.bFrame2InFrontClick(Sender: TObject);
begin
  Frame2.BringToFront;
end;

Thirdly, if you are using align (alTop, alClient) and you wish the "unfocused" frames to shrink (so you can display just a label for expanding again) andshow your desired frame in a large size, you can do something like this :-

procedure TForm1.bMaximizeFrame1Click(Sender: TObject);
begin
  Frame2.Align := alTop;
  Frame2.Height := 20;
  Frame1.Align := alClient;
end;

procedure TForm1.bMaximizeFrame2Click(Sender: TObject);
begin
  Frame1.Align := alTop;
  Frame1.Height := 20;
  Frame2.Align := alClient;
end;

fourthly, you could do the same as above, but not use teh align property, and specifically assign the top, left, width and height.
This would be particularly useful if your "bar" has a scrollbar

procedure TForm1.bResizeFrame1Click(Sender: TObject);
begin
  Frame1.Height := 100;
  Frame2.Top := 104;
  Frame2.Height := 20;
end;

procedure TForm1.bResizeFrame2Click(Sender: TObject);
begin
  Frame1.Height := 20;
  Frame2.Top := 24; // the sum of all the shrunken frames above this one
  Frame2.Height := 100;
end;

hth, Loki
0
 
MerijnBSr. Software EngineerCommented:
TFrame has a .visible property, is that what you need?
0
 
ramboliviaCommented:
Hi senad,

I would suggest you place your frames on a TPageControl.  You can hide the Tabs by setting the TabVisible property to false (this property is on each tab).

It is a good idea to set the TabVisible property to false on runtime so that the tabs can help you during design time.

You can easily switch between frames using the TPageControl.TabIndex property.

Hope it helps!!!!

R.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.