我通过从System.Windows.Forms.TableLayoutPanel继承来创建自己的控件。我需要把行号定为1。
public class KTextPanel : TableLayoutPanel
{
public KTextPanel()
{
ColumnCount = 1;
RowCount = 1;
}
}因此,我在新控件的构造函数中实现了它。问题是,当我在UI设计器上生成新控件的新实例时,UI设计器会自动覆盖blah.designer.cs中的行数和行数。
//
// kTextPanel8
//
this.kTextPanel8.AANAME = "Force Pickup";
this.kTextPanel8.AANODENAME = "picker";
this.kTextPanel8.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.kTextPanel8.ColumnCount = 2;
this.kTextPanel8.RowCount = 2;它看起来2是TableLayoutPanel的默认值。如何防止UI设计人员完成这个自动例程?
发布于 2016-07-19 10:54:01
我认为您可以重写设计器,但是在调用InitializeComponent()之后在表单构造函数中设置您想要的值。或者进入设计器并使用属性窗口在那里设置控件的属性,应该更改设计器生成的内容。
发布于 2016-07-19 11:19:27
使用DefaultValue属性
像这样的事情应该有效:
public class KTextPanel : TableLayoutPanel
{
public KTextPanel()
{
ColumnCount = 1;
RowCount = 1;
}
[DefaultValue(1)]
public new int ColumnCount
{
get
{
return base.ColumnCount;
}
set
{
base.ColumnCount = value;
}
}
//... same for RowCount
}https://stackoverflow.com/questions/38455369
复制相似问题