Position and Size
A control's position is defined by the distance between its top-left corner and the top-left corner of its container. Often, the container is a form, but it could also be a container control like a panel or group box. Similarly, the size is measured as the width and height of the control from the top-left point. By convention, the position measurement is positive in the downward and rightward directions.
Note
In the later chapters on GDI+, you will discover that it is possible to create specialized controls that have irregular boundaries by using the Region property. Chapter 5 previews this technique with irregularly shaped forms.
All values are integers measured in pixels. They are provided through several properties (including Top, Left, Right, and Bottom for position, and Width and Height for size), as shown in Figure 3-3. Although you can manipulate any of these properties, the preferred way for setting position is by using the Location property with a Point structure. Similarly, the preferred way to define size is to use the Size property with a Size structure. These basic structures originate from the System.Drawing namespace.

Figure 3-3: Control measurements
The following code shows how you can set the location and size of a control using the Point and Size structures.
System.Drawing.Point pt = new System.Drawing.Point();
pt.X = 300; // The control will be 300 pixels from the left
pt.Y = 500; // The control will be 500 pixels from the top.
ctrl.Location = pt;
System.Drawing.Size sz = new System.Drawing.Size();
sz.Width = 500;
sz.Height = 60;
ctrl.Size = sz;
// Just for fun, set another control to have the same size.
ctrl2.Size = ctrl.Size;
By importing the System.Drawing namespace and using some handy constructors, you can simplify this code considerably.
ctrl.Location = new Point(300, 500); // Order is (X, Y)
ctrl.Size = new Size(500, 60); // Order is (Width, Height)
This latter approach is the one that Visual Studio .NET takes when it creates code for your controls at design-time. There are other size and position-related properties, such as those used for anchoring and docking when creating automatically resizable forms. These are described in detail in Chapter 5.
Tip
The Visual Studio .NET designer provides a slew of tools that make it easier to lay out controls. Look under the Format menu for options that let you automatically align, space, and center controls.You can also right-click a control and choose to "lock" it in place, ensuring that it won't accidentally be moved while you create and manipulate other controls.