0

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. 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.

marc hoffman
  • 586
  • 1
  • 5
  • 14
ThN
  • 3,235
  • 3
  • 57
  • 115
  • 1
    If you're referring to [this question](http://stackoverflow.com/q/15210229/62576), I couldn't answer it or comment on it because I couldn't even come up with a vague guess at what you were asking. (Just like the version before that one that used the same image, but was confusing as well and wasn't answered, I think.) This one is much clearer, and actually makes it clear what you're asking. Perhaps an edit on the previous one to make it clearer would get you answers there as well. :-) – Ken White Mar 05 '13 at 23:48

1 Answers1

1

If you want to set the Bounds, you need to do it with a rectangle. (Please forgive any syntax mistakes in my examples; my Delphi is a little rusty.)

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.

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.). Setting the Bounds property from the rectangle will be less work.

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351