Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to hide a toolbutton with style=tbsDivider

122 views
Skip to first unread message

Patric Meyer

unread,
Mar 20, 2001, 5:58:17 AM3/20/01
to
Hello!

I have a problem with customizing the buttons of a tool bar. I can show and
hide normal toolbuttons (style = tbsButton), but I can't hide a button with
style = tbsDivider.
I allready tried to change the style before hiding the toolbutton but this
does not work correctly. I also tried to send the windows message
TB_HIDEBUTTON directly but this also does not work.

Does anybody know a solution?
May this be a problem of the windows DLL?

Thanks for help!

Kind regards,

Patric Meyer


john

unread,
Mar 20, 2001, 3:47:32 PM3/20/01
to
"Patric Meyer" wrote

>
> I have a problem with customizing the buttons of a tool bar. I can show
and
> hide normal toolbuttons (style = tbsButton), but I can't hide a button
with
> style = tbsDivider.

You can try faking it.

Drop a TLabel on the toolbar where you want a Divider. TToolbar then
creates a placeholder button of style tbsDivider.
Set
Label.Autosize := False;
Label.Caption := '';
Label.Transparent := False;
Label.Width := 2;

When you set Label.Visible := False the Divider will show
When you set Label.Visible := True the Divider will be hidden by the Label

Therefore

procedure TForm1.ShowFileButtons(V: Boolean);
begin
btFileNew.Visible := V;
btFileOpen.Visible := V;
btFileSave.Visible := V;
lbFileN1.Visible := not V; // is a TLabel
btFilePrint.Visible := V;
end;


john

unread,
Mar 21, 2001, 9:40:11 PM3/21/01
to
Got your reply - best if you post to the group though - things get a bit
disjointed if we jump between the private and public arena . Anyway...

>You wrote:
>This works fine if I hide all the buttons. But it
>doesn't work properly, if I try to hide a button and a divider in the
middle
>of some buttons.
>For example:
>btFileNew btFileOpen btFileSave btDivider1 btFilePrint btDivider2 btImport
>btExport
>
>How to hide the Button btFilePrint and the Divider btDivider2 without
>resolving a gap that is larger than the btDivider1 between the Button
>btFileSave and the button btImport?

I don't know and I don't think it can be done. Probably the best solution
would be to create and destroy the ToolButtons on request. The code below
gives you one way of doing this. Be aware that it is predicated on using a
TActionList.


procedure AddToolButton(AToolBar: TToolBar; AStyle: TToolButtonStyle; ALeft:
Integer; AAction: TAction; AShowHint: Boolean; ATag: Integer);
var
AButton: TToolButton;
begin
AButton := TToolButton.Create(AToolBar);
AButton.Style := AStyle;
AButton.Left := ALeft;
AButton.Action := AAction;
AButton.ShowHint := AShowHint;
AButton.Tag := ATag;
AButton.Parent := AToolBar;
end;

procedure RemoveToolButton(AToolBar: TToolBar; ATag: Integer);
var
Index: Integer;
begin
for Index := AToolBar.ButtonCount-1 downto 0 do
begin
if AToolBar.Buttons[Index].Tag = ATag then
begin
AToolBar.Buttons[Index].Free;
break;
end;
end;
end;


Example of doing ...

procedure TForm1.Button1Click(Sender: TObject);
begin
actFileNew.Visible := CheckBox1.Checked;
actFileOpen.Visible := CheckBox2.Checked;
actFileSave.Visible := CheckBox3.Checked;
actFileN1.Visible := CheckBox4.Checked;
actFilePrint.Visible := CheckBox5.Checked;
ShowFileButtons;

actRunRun.Visible := CheckBox6.Checked;
actRunN1.Visible := CheckBox7.Checked;
actRunCompile.Visible := CheckBox8.Checked;
actRunDebug.Visible := CheckBox9.Checked;
ShowRunButtons;
end;

procedure TForm1.ShowFileButtons;
const
BTN_FILENEW = 1001;
BTN_FILEOPEN = 1002;
BTN_FILESAVE = 1003;
BTN_FILEN1 = 1004;
BTN_FILEPRINT = 1005;
// initialise ButtonExists to true if toolbuttons created at designtime
else set to false
ButtonExists: array[BTN_FILENEW..BTN_FILEPRINT] of Boolean = (False,
False, False, False, False);
begin
if actFileNew.Visible then
begin
if not ButtonExists[BTN_FILENEW] then
AddToolButton(tbrFile, tbsButton, 0, actFileNew, True, BTN_FILENEW);
end
else
RemoveToolButton(tbrFile, BTN_FILENEW);
ButtonExists[BTN_FILENEW] := actFileNew.Visible;

if actFileOpen.Visible then
begin
if not ButtonExists[BTN_FILEOPEN] then
AddToolButton(tbrFile, tbsButton, tbrFile.ButtonWidth, actFileOpen,
True, BTN_FILEOPEN);
end
else
RemoveToolButton(tbrFile, BTN_FILEOPEN);
ButtonExists[BTN_FILEOPEN] := actFileOpen.Visible;

if actFileSave.Visible then
begin
if not ButtonExists[BTN_FILESAVE] then
AddToolButton(tbrFile, tbsButton, tbrFile.ButtonWidth * 2,
actFileSave, True, BTN_FILESAVE);
end
else
RemoveToolButton(tbrFile, BTN_FILESAVE);
ButtonExists[BTN_FILESAVE] := actFileSave.Visible;

if actFileN1.Visible then
begin
if not ButtonExists[BTN_FILEN1] then
AddToolButton(tbrFile, tbsDivider, tbrFile.ButtonWidth * 3, nil,
False, BTN_FILEN1);
end
else
RemoveToolButton(tbrFile, BTN_FILEN1);
ButtonExists[BTN_FILEN1] := actFileN1.Visible;

if actFilePrint.Visible then
begin
if not ButtonExists[BTN_FILEPRINT] then
AddToolButton(tbrFile, tbsButton, tbrFile.ButtonWidth * 4,
actFilePrint, True, BTN_FILEPRINT);
end
else
RemoveToolButton(tbrFile, BTN_FILEPRINT);
ButtonExists[BTN_FILEPRINT] := actFilePrint.Visible;
end;

procedure TForm1.ShowRunButtons;
const
BTN_RUNRUN = 5001;
BTN_RUNN1 = 5002;
BTN_RUNCOMPILE = 5003;
BTN_RUNDEBUG = 5004;
// initialise ButtonExists to true if toolbuttons created at designtime
else set to false
ButtonExists: array[BTN_RUNRUN..BTN_RUNDEBUG] of Boolean = (False, False,
False, False);
begin
if actRunRun.Visible then
begin
if not ButtonExists[BTN_RUNRUN] then
AddToolButton(tbrRun, tbsButton, 0, actRunRun, True, BTN_RUNRUN);
end
else
RemoveToolButton(tbrRun, BTN_RUNRUN);
ButtonExists[BTN_RUNRUN] := actRunRun.Visible;

if actRunN1.Visible then
begin
if not ButtonExists[BTN_RUNN1] then
AddToolButton(tbrRun, tbsDivider, tbrRun.ButtonWidth, nil, False,
BTN_RUNN1);
end
else
RemoveToolButton(tbrRun, BTN_RUNN1);
ButtonExists[BTN_RUNN1] := actRunN1.Visible;

if actRunCompile.Visible then
begin
if not ButtonExists[BTN_RUNCOMPILE] then
AddToolButton(tbrRun, tbsButton, tbrRun.ButtonWidth * 2,
actRunCompile, True, BTN_RUNCOMPILE);
end
else
RemoveToolButton(tbrRun, BTN_RUNCOMPILE);
ButtonExists[BTN_RUNCOMPILE] := actRunCompile.Visible;

if actRunDebug.Visible then
begin
if not ButtonExists[BTN_RUNDEBUG] then
AddToolButton(tbrRun, tbsButton, tbrRun.ButtonWidth * 3, actRunDebug,
True, BTN_RUNDEBUG);
end
else
RemoveToolButton(tbrRun, BTN_RUNDEBUG);
ButtonExists[BTN_RUNDEBUG] := actRunDebug.Visible;
end;


john <jo...@apollo-group.co.nz> wrote in message news:3ab7c317_1@dnews...

Patric Meyer

unread,
Mar 22, 2001, 1:39:55 AM3/22/01
to
>john <jo...@apollo-group.co.nz> schrieb in im Newsbeitrag:
3ab96842_1@dnews...

> Got your reply - best if you post to the group though - things get a bit
> disjointed if we jump between the private and public arena . Anyway...

Hi! I'm new in newsgroups. So now I hope, this message goes to the group.

> I don't know and I don't think it can be done. Probably the best solution
> would be to create and destroy the ToolButtons on request. The code below
> gives you one way of doing this. Be aware that it is predicated on using
a
> TActionList.

I'm going to do it in the way, you descripted it. It seems to be the only
solution for the problem.

Thanks!

Patric


0 new messages