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

标签 c# winforms combobox

你好社区

我对 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); 
    }
}

关于c# - 是否可以为 System.Windows.Forms.Combobox-Control 设置小于 21 像素的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2252443/

相关文章:

c# - ExpressMapper 可以在 Register 函数中取 Interfaces 吗?

c# - 平面图歧视工会

c# - 在 Json 中更改属性的键

c# - 单击按钮为计时器添加时间

c# - 在 C# 中重命名文件组(Windows 窗体应用程序)

c# - 如何使用户控件表现为单选按钮

c# - ItemContainerGenerator.ContainerFromItem() 返回 null 而 VirtualizingStackPanel.IsVirtualizing ="False"

javascript - 无法向组合框中的 ng-model 添加值

javascript - ExtJS 即时更改组合框项目的值

C# 使用窗体加载其他用户控件并访问基本控件或属性