re-position of a text label

  • Thread starter Thread starter tat
  • Start date Start date
T

tat

Hi,

I have a simple question and I can't seem to find what I want after
google-ing.

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?

Thanks,
TAT
 
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
 
Hi,

I have a simple question and I can't seem to find what I want after
google-ing.

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?

Thanks,
TAT

You could clear the Left from the label's Anchor property. If neither
Left nor Right is set, the control will move horizontally by 1/2 of
the size change of the parent. That may not quite keep it centered,
but it will be close.
 
Back
Top