buzcrawl
buzcrawl

Reputation: 103

Consistent look between forms

Say I have 2 forms. Both of them have the same height / width.

Form 1 has a button which opens Form 2.

When I click the button, Form 2 jumps a little bit to a different location than Form 1.

So I guess my question is. how do I set up so this transition is smooth, like the new form is where form1 was.

Do I have to set this up in the properties? Or is there a better way? Right now, both of my forms are default forms. I looked at MDI thing, and that's not what I want. I just wanted to know if there is something I am missing.

Upvotes: 0

Views: 81

Answers (5)

Olivier Jacot-Descombes
Olivier Jacot-Descombes

Reputation: 112612

Use FormStartPosition.Manual as StartPosition, otherwise Windows will determine the start position.

var form2 = new Form2();
form2.StartPostition = FormStartPosition.Manual;
form2.Location = this.Location;
form2.ShowDialog(this);

Upvotes: 0

Tumen_t
Tumen_t

Reputation: 801

You will need to use the Location property of your form as below. The x and y coordinates start at the top left corner. For example, (0,0) would place your form at the top-left window of your screen.

Form1.Location = new Point(x, y);

Upvotes: 1

Z .
Z .

Reputation: 12837

form2.StartPosition = FormStartPosition.CenterParent;
form2.ShowDialog(this);

Upvotes: 1

Selman Genç
Selman Genç

Reputation: 101701

When you open your second form use this:

Form2 secondForm = new Form2();
secondForm.ShowDialog(this);

Then in your Form2 Load event set the location like this:

private void Form2_Load(object sender, EventArgs e)
{
    this.Location = Owner.Location; // Owner is Form1.
}

Upvotes: 2

Servy
Servy

Reputation: 203844

Set the Location of the new form to be the Location of the old form:

newForm.Location = Location;

Upvotes: 0

Related Questions