On 2007-11-29 11:37:01 -0800, randy1200
<ra*******@disc ussions.microso ft.comsaid:
I have two labels on a form. The text for these two labels is assigned at
runtime.
lblLeft lblRight
If the text for lblLeft is wider than the default, the text runs into
lblRight.
How do I make lblLeft automatically expand to the left?
It depends on what behavior exactly you need.
But one solution would be to set the left label to be right-aligned
text, and then position the two controls so that they are flush against
each other (right edge of left label against left edge of right label).
Then the left label's text will always be positioned starting far
enough at the left to always just reach the right label's text.
If you want something more complicated, then you will probably have to
write some code to explicitly position the left label based on its
width, as Igancio suggests.
You _might_ be able to do something by creating a UserControl that
contains your two labels and is the same size as whatever area within
your form you want those two labels to occupy at most, and then doing
something with the Anchor and Dock properties of the labels so that the
left label always fills whatever space is remaining according to your
needs. But I haven't given that much thought, have never tried it
myself, and it could be a wild goose chase trying to do it that way. :)
Pete