Re: re-position of a text label by Bill
Bill
Fri Mar 07 17:49:28 CST 2008
> I create a form with size, say 800x500. I add a text label such that
> it is at the center (400, 50). In the form properties I set
> WindowState to Maximized. However, when I run the code, the text label
> did not automatically adjust so that it can move to the center. My
> question is what properties of the text label do I need to change?
One strategy would be :
1. create an event handler for the parent Form's resize event.
2. in that event handler take care of adjusting the label's position so it
is centered.
3. if you want to get fancier, you could check the WindowState property of
the parent Form in the re-size event and NOT change the position of the
label if the Form was minimized.
4. if you want to get obsessive-compulsive :), and the label size does not
change, you could pre-calculate half its width and height in the Form load
event, store the results in variables, and then re-use those values in the
Form resize event.This might save you some nanoseconds.
best, Bill