Adding control at runtime
-
I have a usercontrol in form1 which has a button in it. When user press this button I create a FORM class and add my usercontrol to it with the code below:
private void MaximizeButton_Click(object sender, EventArgs e) {
Form form = new Form();
Control c = this.Parent;
form.Controls.Add(c);
form.Controls[0].Dock = DockStyle.Fill;
form.Controls[0].Location = new Point(0, 0);
form.ShowDialog();
}The second form shown correctly but the problem is the UserControl disappear from the main form. Any idea? Thanks
Mazy
"This chancy chancy chancy world." -
I have a usercontrol in form1 which has a button in it. When user press this button I create a FORM class and add my usercontrol to it with the code below:
private void MaximizeButton_Click(object sender, EventArgs e) {
Form form = new Form();
Control c = this.Parent;
form.Controls.Add(c);
form.Controls[0].Dock = DockStyle.Fill;
form.Controls[0].Location = new Point(0, 0);
form.ShowDialog();
}The second form shown correctly but the problem is the UserControl disappear from the main form. Any idea? Thanks
Mazy
"This chancy chancy chancy world."hi, you add contol to form,,you should add user control to form .
private void MaximizeButton_Click(object sender, EventArgs e) { userControl1 c = new userControl1(); c.Dock = DockStyle.Fill; c.Location = new Point(0, 0); Form form = new Form(); form.Controls.Add(c); form.ShowDialog(); }
-
hi, you add contol to form,,you should add user control to form .
private void MaximizeButton_Click(object sender, EventArgs e) { userControl1 c = new userControl1(); c.Dock = DockStyle.Fill; c.Location = new Point(0, 0); Form form = new Form(); form.Controls.Add(c); form.ShowDialog(); }
-
Thanks ,it works now but I have one more problem. This button will be placed inside different type of UserControls, so how can get which UserControl should be create other that using a factory for my constructors?
Mazy
"This chancy chancy chancy world."i don't understand exactly ,please explain more phone number : 09124603315 -- modified at 7:36 Monday 25th June, 2007