[英]Set UserControl's max height without setting max width
您可以重写SetBoundsCore
并使它使用ComboBox
高度作为控件的高度:
protected override void SetBoundsCore(int x, int y, int width, int height,
BoundsSpecified specified)
{
base.SetBoundsCore(x, y, width, comboBox1.Height, specified);
}
注意1:如果您的UserControl
仅包含ComboBox
,则最好从ComboBox
派生而不是创建包含ComboBox
的用户控件
注意2:在设计器中,您可以通过创建新的ControlDesigner
并覆盖SelectionRules
属性,使控件仅能从左或向右调整大小。 为此,添加对System.Design
程序集的引用,然后创建一个自定义设计器:
using System.Windows.Forms.Design;
public class MyControlDesigner : ControlDesigner
{
public override SelectionRules SelectionRules
{
get
{
return SelectionRules.LeftSizeable |
SelectionRules.RightSizeable |
SelectionRules.Moveable;
}
}
}
然后就可以通过以下方式用designer属性装饰您的自定义控件:
[Designer(typeof(MyControlDesigner))]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.