Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 如何在设计时设置按钮的精确高度?_Delphi_Toolbar_Delphi 10.1 Berlin - Fatal编程技术网

Delphi 如何在设计时设置按钮的精确高度?

Delphi 如何在设计时设置按钮的精确高度?,delphi,toolbar,delphi-10.1-berlin,Delphi,Toolbar,Delphi 10.1 Berlin,在Delphi 10.1.2 VCL应用程序中,我在TToolBar上有一个TToolButton: object tlbDocProperties: TToolBar AlignWithMargins = True AutoSize = False Left = 1 Top = 28 Width = 422 Height = 28 Margins.Left = 0 Margins.Right = 0 BorderWidth = 1 ButtonWidth

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

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。我在设计时为
t工具按钮
t工具条
尝试了许多不同的设置,但它总是会恢复


因此,如何在设计时将
TToolButton
的高度从22更改为24?

禁用
TToolBar
Show Caption
属性,因为它可以根据标题大小调整按钮的大小

您也可以在这里阅读关于您的问题的一种可能的解决方案

请注意,您也可以手动放置其他按钮,如
t工具栏上的标准
t按钮
t速度按钮
。它们都允许您显示其标题,而无需使用
t工具栏。ShowCaptions
属性已启用,但它们看起来确实不同

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

当使用
Tahoma
作为字体时,我不得不将大小从8增加到11,按钮高度为24


因此,在字体大小方面稍作调整,为自己找到合适的值。

我发现了一个非常实用的解决方案:

我使用16x18图像列表中的16x18图标(宽度=16,高度=18),而不是使用16x16图标作为
t工具按钮

现在,
t按钮的高度会根据需要自动捕捉到24

要将按钮设置为所需高度,请在图标编辑器中通过在图示符的顶部和底部添加大量透明像素来修改图示符的画布高度,例如:

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

Button Height := Image Height + 6
这意味着:如果图示符高度为18,则按钮高度为24;如果图示符高度为20,则按钮高度为26,以此类推


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

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

不幸的是,这些聪明的建议在我的情况下不起作用,因为我需要按钮上的标题。当我在工具栏上关闭
ShowCaptions
时,我可以将按钮高度设置为24,但只要我再次打开
ShowCaptions
,按钮高度就会自动返回到22。我不能使用其他按钮,因为我在应用程序中有几个工具栏,它们都应该是相同的视觉样式。而且我也不能增加字体大小,因为那样会使按钮标题看起来很难看。即使我在工具栏上使用
TSpeedButton
,它的高度也总是回缩到22!我想使用16x18字形,按钮高度为26。我该怎么做呢。这就是问题所在。你能回答这个问题吗?只需使用具有相应高度的标志符号。通过在字形的顶部和底部添加一个透明区域来更改字形的画布大小。您还没有真正回答所问的问题。这次我不会让我挑起:)@user1580348很好。我从来没有想过,通过更改ToolButton图标大小,您也可以影响按钮本身的大小。我会尽量记住这个把戏,因为它有一天会派上用场的。