问题描述
限时送ChatGPT账号..我有一个包含 2 个 forms
、主窗口和第二个 Form
的应用.
I have an app with 2 forms
, the main window and a second Form
.
我想要的是在 button click
上打开第二个 Form
并且它的位置必须在主表单旁边 (所以如果主表单600px
宽,新的 Form
的 X
将是 main.X + 600
)
What I want is to open up the second Form
on a button click
and it's location must be right beside the main form (so if the main form is 600px
wide, the X
of the new Form
will be main.X + 600
)
尝试过这个,但似乎没有用,它仍然在主窗体的顶部打开:
Have tried this but it doesn't seem to take, it opens on top of the main form still:
private void button1_Click(object sender, EventArgs e)
{
var form = new SecondForm();
var main = this.Location;
form.Location = new Point((main.X + 600), main.Y);
form.Show();
}
Location
是不是正确的属性?
推荐答案
将表单的 StartPosition
设置为 FormStartPosition.Manual
.您可以在设计器中或从构造器中完成:
Set your form's StartPosition
to FormStartPosition.Manual
. You can do it in the designer or from the constructor:
StartPosition = FormStartPosition.Manual;
这篇关于Winforms 位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论