简体   繁体   English

控件的边界与设置控件的X,Y,Width,Height有什么区别?

[英]What is the difference between control's bounds and setting X,Y,Width,Height of a control?

So, lets say I have a panel on a winform and I want it displayed at particular point and should have a specific width and height on the winform. 因此,可以说我在winform上有一个面板,我希望它显示在特定点,并且在winform上应该有特定的宽度和高度。 Plus, I want to do it during run-time. 另外,我想在运行时执行此操作。

So, what is the difference and the right way to move and set panel's dimensions? 那么,移动和设置面板尺寸的区别和正确方法是什么?

This way: 这条路:

Panel1.bounds.X:=10;
Panel1.bounds.Y:=10;
Panel1.bounds.width:=100;
Panel1.bounds.height:=103;

Or This way: 或者这样:

Panel1.Left := 10;
Panel1.Top := 10;
Panel1.width:=100;
Panel1.height:=103;

Or Both ways should have the same effect on the panel1. 或两种方式都应在面板上产生相同的效果。

I am trying to figure out what really is wrong with my program...Although I have asked a question specific to my problem, no one even attempted to answer or even able to leave comment. 我正在尝试弄清楚我的程序到底出了什么问题...尽管我问了一个特定于我的问题的问题,但是没有人试图回答甚至发表评论。 So, I am asking bits and piece of question to understand my problem. 因此,我要问一点点问题来理解我的问题。

If you want to set the Bounds , you need to do it with a rectangle. 如果要设置Bounds ,则需要使用矩形。 (Please forgive any syntax mistakes in my examples; my Delphi is a little rusty.) (请原谅我示例中的任何语法错误;我的Delphi有点生疏。)

BoundsRect: Rectangle;
BoundsRect.X = 10;
BoundsRect.Y = 10;
BoundsRect.Width := 100;
BoundsRect.Height := 103;
Panel1.Bounds := BoundsRect;

Typically, you'd use that if you want to set or change multiple properties. 通常,如果要设置或更改多个属性,可以使用该属性。 If you just want to set one or two properties, you can use Width , Top , etc. 如果只想设置一个或两个属性,则可以使用WidthTop等。

One other difference is that every time you set one of those properties (either Bounds , or one of the individual properties), it causes a lot of work behind the scenes (moving and redrawing the window, etc.). 另一个不同之处是,每次您设置这些属性之一( Bounds或单个属性之一)时,都会在幕后进行大量工作(移动和重绘窗口等)。 Setting the Bounds property from the rectangle will be less work. 从矩形设置Bounds属性将减少工作量。

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

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