Winform 自定义控件不允许, 禁止修改高度, 类似TextBox,只能横向调整宽度
// 添加引用 System.Desing;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace WindowsFormsApp2
{
// 引用 System.Design
/// <summary>
/// 自定义控件不允许更改高度
/// </summary>
[System.ComponentModel.Designer(typeof(Designer1))]
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
}
#region 自定义设计类
/// <summary>
/// 自定义设计类
/// </summary>
public class Designer1 : System.Windows.Forms.Design.ControlDesigner
{
/// <summary>
/// 不允许调整控件的高度
/// </summary>
public override SelectionRules SelectionRules
{
get
{
SelectionRules rules = SelectionRules.Visible | SelectionRules.Moveable |
SelectionRules.LeftSizeable | SelectionRules.RightSizeable;
return rules;
}
}
}
#endregion
}