自定义了一个控件
在控件里有一属性如下
ComboBoxItemCollection items;
public ComboBoxItemCollection Items
{
get { return items; }
set {
if (value == null)
value = new ComboBoxItemCollection();
items = value; RecalSize(); }
}
在窗体设置器中使用这控件把它拖进窗体就得
设计器自动生成了代码
private void InitializeComponent()
{
this.comboBoxSelectItemControl1.ActiveColor = System.Drawing.Color.White;
this.comboBoxSelectItemControl1.Items = null;
这里我想让null设计器自动生成的代码为new ComboBoxItemCollection()
需要怎么做
在控件里有一属性如下
ComboBoxItemCollection items;
public ComboBoxItemCollection Items
{
get { return items; }
set {
if (value == null)
value = new ComboBoxItemCollection();
items = value; RecalSize(); }
}
在窗体设置器中使用这控件把它拖进窗体就得
设计器自动生成了代码
private void InitializeComponent()
{
this.comboBoxSelectItemControl1.ActiveColor = System.Drawing.Color.White;
this.comboBoxSelectItemControl1.Items = null;
这里我想让null设计器自动生成的代码为new ComboBoxItemCollection()
需要怎么做
[DefaultValue(..)]之类的
items=new ComboBoxItemCollection();
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent(); this.items = new ComboBoxItemCollection();
}
//设计时,在属性编辑器添加项,自动生成代码
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public ComboBoxItemCollection Items
{
get { return items; }
set
{
if (value == null)
value = new ComboBoxItemCollection();
items = value; RecalSize();
}
} public void RecalSize()
{
}
ComboBoxItemCollection items;
} public class ComboBoxItemCollection : ComboBox.ObjectCollection//不知道你的ComboBoxItemCollection 怎么定义,我随便找个代替,不影响本问题
{
public ComboBoxItemCollection()
:base(new ComboBox())
{
}
}
自动生成Item代码 //
// userControl11
//
new WindowsFormsApplication1.ComboBoxItemCollection().AddRange(new object[] {
((object)(resources.GetObject("userControl11.Items")))});
this.userControl11.Location = new System.Drawing.Point(70, 53);
this.userControl11.Name = "userControl11";
this.userControl11.Size = new System.Drawing.Size(150, 150);
this.userControl11.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.userControl11);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
{
if(items=null)
items = new ComboBoxItemCollection();
return items;
}
set
{
if (value == null)
value = new ComboBoxItemCollection();
items = value; RecalSize();
}