|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Label Expand LeftI 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? Thanks, Randy Hi,
I'm not sure if this is doable, first take a look at Label.RightToLeft. Otherwise you will have to calculate the position of label 2. using Label.Width (or Graphics.MeasureString) you can determine the width lf lblLeft and then position lblRight accordingly. Show quote "randy1200" <randy1***@discussions.microsoft.com> wrote in message news:8DF2432F-C5A1-4F45-93D4-FCC34215DDE1@microsoft.com... >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? > > Thanks, > Randy On 2007-11-29 11:37:01 -0800, randy1200
<randy1***@discussions.microsoft.com> said: > I have two labels on a form. The text for these two labels is assigned at It depends on what behavior exactly you need.> 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? 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 Assuming you don't want to add custom code and that this is a regular
windows form, you may want to take a look at the "TableLayoutPanel control". You can configure that thing so that the label wraps in multiple line if it does not fit on the table cell or make the cell grow with the label pushing the label on the right without overlapping. Not sure if this would do what you want but you may want to give it a shoot. |
|||||||||||||||||||||||