Reputation: 1287
I had two forms - form "main" and form "alert".
I've changed Form "alert" to userControl,
Here is the code in form "main".
alert = new AlertForm();
alert.TopLevel = false;
alert.Visible = true;
this.pnlData.Controls.Add(alert);
alert.Canceled += new EventHandler<EventArgs>(buttonCancel_Click);
alert.Show();
pnlData is a panel inside the form "main"
When I try to run, the userControl is overlapping like this,
how to fix that? how to bring userControl in front of the label and textbox in pnlData?
Upvotes: 0
Views: 471
Reputation: 19330
I could reproduce your problems. This is the code that got rid of it:
public Form1() // constructor
{
InitializeComponent();
Form f = new Form2();
f.TopLevel = false;
panel1.Controls.Add(f);
f.BringToFront();
// Edit: if you want to change Top - do similar thing to Y
f.Location = new Point((int)(panel1.Size.Width / 2 - f.Size.Width / 2), 0);
f.Show();
}
Works perfect - form is moving inside panel
Upvotes: 1