maxfax
maxfax

Reputation: 4305

Delphi: 3 Tool Buttons - 3 Frames = switching

I have 3 grouped Tool Buttons (a Tool Bar). One of them is always down. And I have 3 frames. What is the easiest and right way to change the frames switching among the buttons?

Thanks!

Upvotes: 1

Views: 692

Answers (2)

RobertFrank
RobertFrank

Reputation: 7394

If the frames are all in the same position on the screen, then doing it the way the Sertac suggests will make it really cumbersome to see in the IDE what they look like on their owner form

I suggest you put the frames in a page control or tab control.

Upvotes: 1

Sertac Akyuz
Sertac Akyuz

Reputation: 54792

The right way is moot at best. One of the easiest ways of many can be to set unique Tags for the grouped buttons, f.i. 0, 1, 2, then set all of the three button's 'OnClick' to the same handler and show one of your frames according to the tag of the clicked button and hide the others:

procedure TForm1.ToolButton1Click(Sender: TObject);
begin
  Frame1.Hide; // will return immediately if already hidden
  Frame2.Hide;
  Frame3.Hide;
  case TToolButton(Sender).Tag of
    0: Frame1.Show;
    1: Frame2.Show;
    2: Frame3.Show;
  end;
end;

This is assuming you've already put the frames on your form at design time. Don't forget setting the Grouped property of the buttons and their Styles to 'tbsCheck'.

Upvotes: 3

Related Questions