hei。 我能够解决它通过使用列表(通用列表)
在主窗体中,创建一个私人的变异名单 并创建公共方法来获取变量。
在主窗体中,通过循环列表创建一个公共方法来添加。
所以在我创建的新班级中,在方法i 之一放置了窗体的创建。并进入这里我通过listcontrol。
然后把所有的控制变量放到列表控件中。
并点击按钮,我调用类方法,然后它会自动绘制由该类创建的表单控件。
private List<Control> listControl;
public windowForm()
{
InitializeComponent();
listControl = new List<Control>();
}
public List<Control> ListControl {
get { return listControl; }
}
public void addControl() {
if (this.listControl.Count() > 0) {
foreach (Control c in listControl)
{
Console.WriteLine("adding "+c.Name);
this.panel1.Controls.Add(c);
}
}
}
public void removeControl() {
if (this.listControl.Count() > 0)
{
foreach (Control c in listControl)
{
Console.WriteLine("removing " + c.Name);
this.panel1.Controls.Remove(c);
}
}
}
和我创建了新的类,我把
this.groupbox_VectorAddition = new System.Windows.Forms.GroupBox();
this.txtBox_v1a = new System.Windows.Forms.TextBox();
this.txtBox_v1b = new System.Windows.Forms.TextBox();
this.txtBox_v1c = new System.Windows.Forms.TextBox();
this.txtBox_v2c = new System.Windows.Forms.TextBox();
this.txtBox_v2b = new System.Windows.Forms.TextBox();
this.txtBox_v2a = new System.Windows.Forms.TextBox();
this.lbl_Vector1 = new System.Windows.Forms.Label();
this.lbl_Vector2 = new System.Windows.Forms.Label();
this.btn_countAddVector = new System.Windows.Forms.Button();
this.btn_resetVector = new System.Windows.Forms.Button();
//put everything into the panel
form.ListControl.Add(btn_resetVector);
form.ListControl.Add(btn_countAddVector);
form.ListControl.Add(lbl_Vector2);
form.ListControl.Add(lbl_Vector1);
form.ListControl.Add(txtBox_v2a);
form.ListControl.Add(txtBox_v2b);
form.ListControl.Add(txtBox_v2c);
form.ListControl.Add(txtBox_v1c);
form.ListControl.Add(txtBox_v1b);
form.ListControl.Add(txtBox_v1a);
form.ListControl.Add(groupbox_VectorAddition);
还没有成功地应用此 – r4ccoon 2009-09-28 06:49:38
我试图做一个单独的文件和类。我想我必须通过主窗体变量。 – r4ccoon 2009-09-28 07:45:57
我有一个FormUI_VectorAddition类,并且我有方法InitializeComponent(Control control,windowForm form) control实际上是一个面板。 control.SuspendLayout(); form.SuspendLayout(); control.Controls.Add(this.txtBox_v1a); this.txtBox_v1a = new System.Windows.Forms.TextBox(); control.ResumeLayout(false); control.PerformLayout(); form.ResumeLayout(false); – r4ccoon 2009-10-01 01:25:19