如何在设计时设置TToolButton的精确高度?

时间:2017-04-13 19:33:48

标签: delphi toolbar delphi-10.1-berlin

在Delphi 10.1.2 VCL应用程序中,TToolButton上有TToolBar

object tlbDocProperties: TToolBar
  AlignWithMargins = True
  AutoSize = False
  Left = 1
  Top = 28
  Width = 422
  Height = 28
  Margins.Left = 0
  Margins.Right = 0
  BorderWidth = 1
  ButtonWidth = 148
  Color = clBtnFace
  DoubleBuffered = True
  EdgeInner = esNone
  EdgeOuter = esRaised
  Images = cxImageList16Bookmarks
  Indent = 5
  List = True
  ParentColor = False
  ParentDoubleBuffered = False
  ShowCaptions = True
  TabOrder = 0
  Transparent = False
  object btnEditDocProps: TToolButton
    AlignWithMargins = False
    Left = 5
    Top = 0
    Height = 22
    Down = False
    AutoSize = False
    Caption = 'Edit Document Properties'
    ImageIndex = 56
    Style = tbsCheck
    OnClick = btnEditDocPropsClick
  end
end

每当我尝试在设计时将TToolButton的高度从22更改为24时,它会自动快速回到22.我为TToolButton和{{I}}尝试了许多不同的设置{1}}在设计时但它总是快速恢复。

那么如何在设计时将TToolBar的高度从22改为24?

3 个答案:

答案 0 :(得分:1)

我找到了一个非常实用的解决方案:

我没有使用TToolButton的16x16图标,而是使用16x18 ImageList中的16x18图标(宽度= 16,高度= 18)。

现在TToolButton的高度会根据需要自动捕捉到24!

要将按钮设置为所需高度,请在图标编辑器中修改字形的画布高度,方法是在字形的顶部和底部添加一些透明像素,例如:

enter image description here

使用上面的TToolBar示例,我从几个测试中得出了这个经验规则:

Button Height := Image Height + 6

这意味着:如果字形高度为18,则按钮高度为24,字形高度为20,按钮高度为26,等等。

请记住:这仅适用于上述配置,即ToolBar.List = TrueToolbar.ShowCaptions = True时。当然,您需要一个ToolBar.Images ImageList,其中ImageList.Height与字形高度匹配。

答案 1 :(得分:0)

禁用Show Caption的{​​{1}}属性,因为它可能会导致按钮根据字幕大小调整大小

TToolBar.ShowCaptions

您还可以在此处阅读有关您问题的一种可能解决方案

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

请注意,您也可以手动放置TToolBar上的标准TButtonTSpeedButton等其他按钮。它们都允许您显示其标题而无需使用TToolbar属性,但它们看起来不同。

编辑:将TToolBar按钮的高度增加到24的另一个解决方案是增加TToolBar.ShowCaptions

当使用TToolBar.Font.Size作为字体时,我必须将大小从8增加到默认为11以使按钮高度为24。

因此,请稍微使用字体大小来为自己找到合适的价值。

答案 2 :(得分:0)

在面板中有工具栏。 将面板字体大小和类型设置为您喜欢的任何内容。 在工具栏中,将父字体设置为“True”。 工具栏按钮大小将自动调整以与它所在面板的字体一致。 然后只需调整该面板的字体大小和类型,直到获得所需的工具按钮大小。 您不需要在工具栏中打开或关闭 ShowCaption。没关系。 问候 格雷姆

相关问题