我想在C#中将两个表单放在彼此旁边

Pee*_*Haa 7 c# positioning winforms

我有一个表单打开另一个表单.

我想要做的是将新打开的表单放在下一个(右侧)到已经可见的表单上.

所以我需要将新表单放在当前表单结束的位置(如果错误则纠正我).

所以我需要做一些事情:

newform.Left = this.endposition.right;
Run Code Online (Sandbox Code Playgroud)

endposition属性是我刚刚编写的(伪代码).

如何获得当前表单右侧的结束位置?

编辑

我已经尝试了几种解决方案,但直到现在它们都没有工作.

我总是得到相同的结果:

为什么会发生这种情况http://s1.postimage.org/f4fsbc6pa/why_o_why.png

我试过以下代码:

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);
Run Code Online (Sandbox Code Playgroud)

Eclyps19建议只是手动添加一些像素来定位新表格,虽然我不确定每个系统上的边框是否相同.

Gre*_*ora 10

这对我有用:

        Form1 nForm = new Form1();
        nForm.Show();
        nForm.SetDesktopLocation(this.Location.X + this.Size.Width, this.Location.Y);
Run Code Online (Sandbox Code Playgroud)


Ale*_*ger 3

尝试

newform.Left = oldform.Right + SystemInformation.BorderSize.Width;
Run Code Online (Sandbox Code Playgroud)

这应该将边框的宽度(以像素为单位)添加到 oldform.Right 值中。您可以将 SystemInformation.BorderSize.Width 替换(或添加)为您喜欢的任何整数。