【问题标题】:How to increase the size of the buttons on a tool strip?如何增加工具条上按钮的大小?
【发布时间】:2010-08-07 21:01:29
【问题描述】:

我在表单中添加了一个工具条。在这个工具条中,我在添加工具条按钮的帮助下有一些按钮。这些按钮的默认大小为 22、20。但我想将按钮的大小更改为 25、50。我通过更改 size 属性在设计器中进行了更改,但它没有反映在我的表单中。即使我改变工具条的高度,它也不会改变。有什么帮助吗?

【问题讨论】:

    标签: winforms c#-3.0


    【解决方案1】:

    如果您将 ToolStripButton 的 AutoSize 属性更改为 false,您将能够更改按钮的宽度。

    如果您将 ToolStrip 的 AutoSize 属性更改为 false,您将能够更改其高度,并且 ToolStripButton 将自动更改其高度以适应工具条。

    编辑: 如果您不仅要增加按钮的大小,还要增加按钮图像的大小,则必须使用较大的图像,或者您可以尝试调整原始图像的大小。然后您还必须更改工具条的ImageScalingSize 属性。尝试使用以下代码:

    //change the dimensions of button itself
    toolStrip1.AutoSize = false; toolStrip1.Height = 50;
    toolStripButton1.AutoSize = false; toolStripButton1.Width = 50;
    
    //resize the image of the button to the new size
    int sourceWidth = toolStripButton1.Image.Width;
    int sourceHeight = toolStripButton1.Image.Height;
    Bitmap b = new Bitmap(40, 40);
    using (Graphics g = Graphics.FromImage((Image)b))
    {
       g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
       g.DrawImage(toolStripButton1.Image, 0, 0, 40, 40);
    }
    Image myResizedImg = (Image)b;
    
    //put the resized image back to the button and change toolstrip's ImageScalingSize property 
    toolStripButton1.Image = myResizedImg;
    toolStrip1.ImageScalingSize = new Size(40, 40);
    

    【讨论】:

    • 嗯,它改变了工具条按钮的大小,如你所愿......所以我想你真正想要做的就是调整图像按钮的大小......我已经编辑了我的答案。 ..
    • 谢谢!有效。是否可以在表单的右端以一种形式将两个工具条一个接一个地放置?
    • 我取消了工具条的停靠,但现在工具条上的按钮消失了。它们仅在我单击底部的小箭头时出现。请问有什么办法吗?
    • 很高兴知道图像比例大小属性
    【解决方案2】:

    只是

    toolStrip1.ImageScalingSize = new Size(40, 40);
    

    就是这样;)

    【讨论】:

      【解决方案3】:

      最简单的解决方案:

      只需更改属性工具栏上工具条的 ImageScalingSize 属性即可。

      就是这样:)

      【讨论】:

        猜你喜欢
        • 2022-01-24
        • 2023-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-03
        • 1970-01-01
        • 2020-01-16
        • 1970-01-01
        相关资源
        最近更新 更多