简体   繁体   English

如何使控件的右边缘与Windows窗体窗口的右边缘交叉?

[英]How to cross the Right edge of a control with the Right edge of the Windows Form window?

I'm working C# Winform. 我正在使用C#Winform。

And have a Label control which name is: lblName 并具有一个名称为: lblNameLabel控件。

I want to set the position of this control as: It's the Right side been cross to the Right side of the it's parent Windows Form . 我想将此控件的位置设置为:它的右侧已与父Windows Form的右侧交叉。

I used the code below: 我使用下面的代码:

this.lblName.Left = this.Width - this.lblName.Width;

In the Windows Form code. 在Windows窗体代码中。

But the lblName control been exits the border of the page and seems the this.Width is larger than the Windows form window Width! 但是lblName控件已退出页面的边框,并且似乎this.Width大于Windows窗体窗口的Width!

Where is my mistake and what is wrong? 我的错误在哪里,什么是错误的?

The Width property includes the width of the borders. Width属性包括边框的宽度。

Instead, you should use the ClientRectangle property, which does not include borders. 相反,应该使用不包含边框的ClientRectangle属性。

lblName.Left = this.ClientRectangle.Width - lblName.Width;

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

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