Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to position two forms right next to each other in C#

I have one form which opens another form.

What I want to do is position the newly opened form right next (on the right side) to the already visible form.

So I need to position the new form to where the current form ends (correct me if wrong).

So I will need to do something like:

newform.Left = this.endposition.right;

The endposition property is something I just made up (pseudo code).

How to get the end position on the right side of the current form?

EDIT

I've tried several solutions but until now none of them worked.

I always get the same result:

Why does this happen

I've tried the following codes:

newform.Left = this.Right + SystemInformation.BorderSize.Width;

newform.Left = this.Right + (SystemInformation.BorderSize.Width * 2);

newform.SetDesktopLocation(this.Location.X + this.Size.Width, this.Location.Y);

Eclyps19 suggested to just manually add some pixels to position the new form, although I'm not sure whether the border will be the same on every system.

like image 620
PeeHaa Avatar asked Aug 26 '11 17:08

PeeHaa


2 Answers

This works for me:

        Form1 nForm = new Form1();
        nForm.Show();
        nForm.SetDesktopLocation(this.Location.X + this.Size.Width, this.Location.Y);
like image 64
Greg Andora Avatar answered Sep 23 '22 07:09

Greg Andora


Try

newform.Left = oldform.Right + SystemInformation.BorderSize.Width;

This should add the width (in pixels) of the border to the oldform.Right value. You can replace (or add to) SystemInformation.BorderSize.Width with any integer you'd like to fit your liking.

like image 43
Alec Sanger Avatar answered Sep 26 '22 07:09

Alec Sanger