Winforms 位置

编程入门 行业动态 更新时间:2024-10-28 18:23:33
本文介绍了Winforms 位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个包含 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 11:28:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1115275.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位置   Winforms

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!