Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does a TToolBar calculate button widths automatically when ShowCaption is set True?

I need to have two TToolBars on the right side of my main form, so I put three TPanels for alignment, and then put the TToolBars inside them. I've been trying to tell the toolbuttons to have the same width for the past day, to no avail. Here's a screen shot of what I've got: enter image description here

I found out that if ShowCaption is set to True, the toolbars calculate the button width automatically. My question is why, and how to disable this?

like image 931
iMan Biglari Avatar asked Nov 24 '22 04:11

iMan Biglari


1 Answers

Take a look at this approach:

  1. Set Autosize to False for all buttons.
  2. Call the following inside Form’s OnCreate event: SendMessage(ToolBar3.Handle,TB_SETBUTTONWIDTH, 0, MAKELPARAM(0, <DEFAULT_WIDTH_THAT_YOU_WANT_TO_SET>));
  3. Make sure you do not alter the Visible property of any buttons before the above call – as it will fail for those buttons that are not visible.
  4. Also, ensure you have “CommCtrl” in the uses list for TB_SETBUTTONWIDTH message.

For more details: http://zarko-gajic.iz.hr/ttoolbars-ttoolbutton-autosize-width-issues-empty-caption/

like image 197
Fernando Ghisi Avatar answered Dec 18 '22 16:12

Fernando Ghisi