Click to See Complete Forum and Search --> : Labels


Lev FatMan
June 17th, 2001, 04:20 AM
Hello
I know thats a stupid question but anyhow I could not find its answer , while using a label if it caption is too long , its automatically write the rest in a new line. Where can I change it and make it stay in the same line.

FatMan

Cakkie
June 17th, 2001, 06:38 AM
First of all, there's no such thing as a stupid question, there are only stupid answers.
Second of all, about your question. The label control has an autosize property, which will make the label larger if the text doesn't fit. But I think this only appies to the height. But we wouldn't be calling use guru's if we didn't know a workaround. The form object has a property TextHeight and TextWidth, which return the width or height of a textstring. Note that this is in the font set by the font property of the form, so you need to make sure it is the same fot the label your checking.

label1.width = 240 + Form1.TextWidth(label1.caption)



Note that I added 240 to the width, to give it some extra space, otherwise, it might turn out that the text doesn't fit the line afterall.

Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

Cimperiali
June 18th, 2001, 04:28 AM
10 for answer on thecnical matter and:
>there's no such thing as a stupid question[...]
this deserve another 10 point, but I can give you only one.
Cheers,
Cesare

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.

John G Duffy
June 18th, 2001, 11:14 AM
The label control has a WordWrap property that is supplsed to do what you want. I just have not been able to get it to work. Here is an excerpt from MSDN
WordWrap Property
See Also Example Applies To

Returns or sets a value indicating whether a Label control with its AutoSize property set to True expands vertically or horizontally to fit the text specified in its Caption property.

Syntax

object.WordWrap [= boolean]

The WordWrap property syntax has these parts:

Part Description
Object An object expression that evaluates to an object in the Applies To list.
Boolean A Boolean expression specifying whether the Label expands to fit the text, as described in Settings.


Settings

The settings for boolean are:

Setting Description
True The text wraps; the Label control expands or contracts vertically to fit the text and the size of the font. The horizontal size doesn't change.
False (Default) The text doesn't wrap; the Label expands or contracts horizontally to fit the length of the text and vertically to fit the size of the font and the number of lines.


Remarks

Use this property to determine how a Label control displays its contents. For example, a graph that changes dynamically might have a Label containing text that also changes. To maintain a constant horizontal size for the Label and allow for increasing or decreasing text, set the WordWrap and AutoSize properties to True.

If you want a Label control to expand only horizontally, set WordWrap to False. If you don't want the Label to change size, set AutoSize to False.

Note If AutoSize is set to False, the text always wraps, regardless of the size of the Label control or the setting of the WordWrap property. This may obscure some text because the Label doesn't expand in any direction.

If both AutoSize and WordWrap are set to True, text will wrap without increasing the size of the Label control, unless a single word is entered that is larger than the width of the Label. In that case, the AutoSize property takes priority and the width of the Label increases to accommodate the long word.




--------------------------------------------------------------------------------

Send feedback on this article. Find support options.

© 2000 Microsoft Corporation. All rights reserved. Terms of use.


John G