2010-02-12 34 views
1

你好社區是否有可能設置高度小於21個像素的System.Windows.Forms.Combobox-控制

我有一個問題與System.Windows.Forms的高度。組合框 - 控制。我無法改變它。我想用它來編寫自己的實現(所有者繪製自定義控件)。

以下代碼不適用於我(僅限於嘗試)。高度仍然是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); 
    } 
} 

請幫幫我。

Regars, 馬科

+0

你使用的minimumSize? – serhio 2010-02-12 14:38:29

+0

好吧,thx爲我沒有設置我即是我的例子。但它不起作用! – 70sCommander 2010-02-12 14:49:39

+0

製作自己的組合如何? – Luiscencio 2010-02-12 15:16:13

回答

4

組合框的高度應根據該字體分配給它 被調整大小 。

因此,更改組合字體。見another discussion on this subject

組合框的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); 
    } 
} 
+1

好的...我的問題的答案是肯定不是!如果你不想改變字體大小! – 70sCommander 2010-02-12 15:28:56

相關問題