hei.
i am able to solve it by using list (generic list)
in main form, create a private variabel List
and create public method to get the variable.
in main form, create a public method to add by looping through the list.
so in the new class i have created, in one of the method i
put the creation of the form. and into here i pass the listcontrol.
and then put all the control variable into the list control.
and on a click of a button, i call the class method, and then it will automatically draw the form controls that created by the class.
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);
}
}
}
and for the new class i have created, i put
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);