Skip to main content
 首页 » 编程设计

c#之是否可以为 System.Windows.Forms.Combobox-Control 设置小于 21 像素的高度

2024年02月24日18artech

你好社区,

我对 System.Windows.Forms.Combobox-Control 的高度有疑问。我无法改变它。我想用它来编写自己的实现(所有者绘制的自定义控件)。

以下代码对我不起作用(只能尝试)。高度还是21px!

public class TestBox : ComboBox 
{ 
    public TestBox() 
    { 
        DropDownHeight = 15; 
    } 
 
    protected override Size DefaultSize 
    { 
        get 
        { 
            return new Size(15,15); 
        } 
    } 
 
    protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) 
    { 
        base.SetBoundsCore(x, y, 15, 15, specified); 
    } 
} 

请帮帮我。

祝好, 马可

请您参考如下方法:

The ComboBox height should be resized based on the font that is assigned to it.

因此,更改组合字体。见another discussion on this subject .

ComboBox 的 MinimumSize 属性编码如下:

public override Size MinimumSize 
{ 
    get 
    { 
        return base.MinimumSize; 
    } 
    set 
    { 
        // can see that Height is not taken in consideration - is 0 
        base.MinimumSize = new Size(value.Width, 0);  
    } 
}