delphi – TToolButton高度随Style = tbsDropdown增长

前端之家收集整理的这篇文章主要介绍了delphi – TToolButton高度随Style = tbsDropdown增长前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我注意到当你将按钮的样式设置为tbsDropdown时,TToolButton的高度会增加.我可以理解宽度增加,所以按钮有空间来绘制向下箭头,但我不确定是否需要增加高度.

重现问题的步骤(Delphi 2010,Windows 7 x64):

>将TToolbar添加到表单,ShowCaptions = True
>右键单击以向工具栏添加按钮
>设置按钮Style = tbsDropDown并注意按钮的高度增长

当分配图像时,会发生相同的高度增加
工具栏,在这种情况下,已经有更多的垂直空间可用
在按钮中绘制下拉列表.

这是一个直观的例子:
alt text http://img440.imageshack.us/img440/1462/ttoolbar02.png
alt text http://img291.imageshack.us/img291/966/ttoolbar01.png

是否有一个解决方法,没有黑客攻击VCL,或者这是硬编码到Windows控件?

解决方法

它是底层Windows控件的一部分.快速浏览一下ComCtrls可以看出,更改TToolButton.Style会调用它的SetStyle方法.如果在SetStyle中,ShowCaptions为True,则TToolBar.ButtonWidth和ButtonHeight都设置为0,并调用TToolButton.RecreateButtons.

反过来,RecreateButtons调用TToolBar.ResizeButtons,它只是使用一个消息发送(发布)到ToolBar

Perform(TB_AUTOSIZE,0);

根据MSDN,TB_AUTOSIZE旨在使用

after causing the size of a toolbar to change either by setting the button or bitmap size or by adding strings for the first time.

由于SetStyle将ButtonWidth和ButtonHeight都设置为0,因此似乎正确发送了此消息.

原文链接:https://www.f2er.com/delphi/101828.html

猜你在找的Delphi相关文章