How do you spawn User Controls programmatically?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a few user controls and I don't want to add them to the main form. I simply want to be able to spawn them like pop-up windows

I added them to my project and call show(), but nothing happens. Any help would be appreciated.
 
Shane Molton said:
I have a few user controls and I don't want to add them to the main form.
I simply want to be able to spawn them like pop-up windows.
I added them to my project and call show(), but nothing happens. Any help
would be appreciated.

put them on a dialog, and show the dialog? You can't just make a control
appear on the screen. It's got to be on something, usually some sort of
form.

HTH,
Eric
 
Shane,

You should create a "blank" dialog, and then dynamically create the
control(s) on the dialog as needed. Here's a sample member function
of such a dialog which can create a user control on demand and display
it:

private void AddMyControl()
{
MyControl ctl = new Testx.MyControl();
//
// myControl1
//
ctl.Location = new System.Drawing.Point(136, 24);
ctl.Name = "myControl1";
ctl.Size = new System.Drawing.Size(176, 96);
ctl.TabIndex = 0;
ctl.Visible = true;
ctl.Show();
this.Controls.Add(ctl);
}

Good luck,
Les Matheson
Integral Concepts, Inc.
http://www.ivsds.com
 
Back
Top