Winforms 位置 [英] Winforms Location

查看:20
本文介绍了Winforms 位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 2 个 forms、主窗口和第二个 Form 的应用.

I have an app with 2 forms, the main window and a second Form.

我想要的是在 button click 上打开第二个 Form 并且它的位置必须在主表单旁边 (所以如果主表单600px 宽,新的 FormX 将是 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆