Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create new form on same screen position

I want to create a new form on the same location. When I call this code a new form opens but on a different screen position.

private void BtnAddForm_Click(object sender, EventArgs e)
{
     Form2 form2 = new Form2();
     form2.Tag = this;
     form2.Location = this.Location;
     form2.Show(this);
     Hide();
}

I used this.Location to get the location from my first form but this has no effect.

like image 661
user3644817 Avatar asked Mar 14 '23 20:03

user3644817


1 Answers

You need to set StartPosition property to Manual for this to work.

private void BtnAddForm_Click(object sender, EventArgs e)
{
    Form2 form2 = new Form2();
    form2.Tag = this;
    form2.StartPosition = FormStartPosition.Manual;         
    form2.Location = this.Location;
    form2.Show(this);
    Hide();
}
like image 197
Harsh Avatar answered Mar 28 '23 09:03

Harsh