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

我与影子孤独终老i 提交于 2020-01-03 15:25:07

问题


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:

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?


回答1:


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/




回答2:


You can use object inspector to set the button width with static value, or you can use formcreate or onpaint or onresize etc to set the value dynamically........



来源:https://stackoverflow.com/questions/15219524/why-does-a-ttoolbar-calculate-button-widths-automatically-when-showcaption-is-se

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!