I understand I must use the location property, am I right?
The Location property of a System.Windows.Forms.Control is a Point
structure. The Point has an X and a Y member. The X member defines the
distance (in pixels) of the left edge of the control from the left edge of
the client area of the Container Control it resides in. The Y member defines
the distance (in pixels) of the top edge of the control from the top edge of
the client area of the Container Control it resides in.
Now I want to center the calendar on the form so that its edges are
equally far from the upper, right, left and bottom borders of the form.
Knowing what I've just told you, it's a simple Math problem. A Control is a
rectangle that occupies a certain area in its parent rectangle. The Control
has a Width and a Height property as well. Taking each of these in turn, the
Width of the parent rectangle minus the width of the Control rectangle
yields the total amount of space available on both sides. Half of the width
of the Control rectangle defines its center. Half of the parent Control
rectangle defines the center of the parent Control rectangle. To center the
Control in the parent Control, the center of the Control must coincide with
the center of the parent Control. As the X member of the Location property
defines the distance from the left edge of the parent Control, the X member
of the Location property of the Control must be half of the width of the
Parent Container minus half the width of the Control:
Parent: 100 pixels wide
0---------------25---------------50---------------75---------------100
Control: 50 pixels wide
0---------------25---------------50
1/2 of the Parent's width = 50.
1/2 of the Control's width is 25.
50 - 25 = 25.
The X position of the Control must be 25 in order to leave the same number
of pixels on the left as on the right.
Apply the same Math to get the Y member of the Location property, and you're
done!
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.