03-03-2004, 10:18 AM
If I have a label and I center the text in the middle, how can I make it so that the text is aligned in the middle from top to bottom as well? When I have one line of text in a label that is twice as big, for example, the text always appears at the top. Is there a property that I can use to do this?
03-03-2004, 10:42 AM
You need to adjust the vertical size of your label to match the text inside. The quick and easy way to do this is to set the Autosize property to TRUE and then set it to FALSE. Once you have done this, the Height property is set to match the size of the font you are using. You'll need to readjust if you change fonts obviously, but if you are just doing these things at design time that isn't a problem.
If you are making changes at run time but aren't changing fonts you shouldn't have any trouble either, just keep the height of the control fixed and you'll be fine. If you need to change fonts, etc. then you can use the TextHeight Method (only available on a Form, Picture Box and Printer objects) to determine how tall to make your label (but since this doesn't apply to the label you'd have to have a different object set with the same font, etc. to have TextHeight return the correct value).
03-03-2004, 11:08 AM
I'm not so sure we're on the same wavelength here. I have a label that is bigger than the text that will go inside. I don't want to shrink the label to fit the text, but instead, position the text dead center in the middle of the label...
03-03-2004, 12:11 PM
There are always a half dozen ways to skin a cat. I've actually used something along the lines of what webbone describes. You do want to change the size of your label. You emulate the effect you're looking for by using a second empty label to define your border style or what ever underneath your 'main' label in question. I'd love to know if there is a better way to tackle this, but this should work...
i threw together a quick form with some buttons to demonstrate this technique.
Label1 is my "Main" label that gets my text
Label2 is simply the boarder
I adjust the location of label1 inside the area covered by label 2
03-03-2004, 12:17 PM
Thanx a lot, much appreciated! :)