简体   繁体   English

如何获得C#表格的宽度?

[英]How to get width of C# Form?

I'm making a text editor, and it will have the ability to be resized. 我正在做一个文本编辑器,它将可以调整大小。 However when it is resized the close button along with a few other buttons at the top are kinda stuck in the middle. 但是,当调整其大小时,关闭按钮以及顶部的其他一些按钮都卡在中间。 I would like to do something like this. 我想做这样的事情。

Ex. 例如

 private void Size_Change(object sender, EventArgs e) // Event after maximize or restore
    {
        Close_Button.Location = Width - (width of button);
    }

what is a method of doing getting the width of a form and then subtracting from that width? 获取表单的宽度然后从该宽度中减去的方法是什么?

Just use anchor points on the button. 只需在按钮上使用锚点即可。 Like Sani Singh Huttunen said. 就像萨尼·辛格·哈特恩(Sani Singh Huttunen)所说。 It's located in the properties of the button. 它位于按钮的属性中。

That way it will be resized or relocated with the form 这样,它将被调整大小或使用表格重新放置

you need change "Location" to "Left" property: 您需要将“位置”属性更改为“左”属性:

private void Size_Change(object sender, EventArgs e) 
    {
        Close_Button.Left = this.Width - Close_Button.Width;
    }

or create new Point to Location property. 或创建新的“指向位置”属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM