|
-
Jul 26th, 2000, 07:49 PM
#1
Thread Starter
Lively Member
If the length of caption of a label is greater than the width of the label, then the caption text is wrapped and fed on to the next line. However, if the label box dimensions are to be kept fixed, the height of the label may not be enough high to display both lines. Thus, the first line and below that some garbled looking part of the next line will be displayed. This, certainly is ugly. Since the font types, sizes, and names are variable, it is not possible to directly estimate the length of the text. This would mean that, it is not possible to put a certain limit of text width quantity and trial that. My question is, how can I detect the occasion, in which a secondly line is generated, and where should I break up this text so tah those things will not be appearing under my cut-off text.
Could I make it clear?
Kiziltan Yuceil
Freelance Web/VB/VBA Programmer
"It's not what you know it's to whom you consult and with whom you collaborate"
-
Jul 26th, 2000, 08:18 PM
#2
Hyperactive Member
Off the top of my head
A couple of things I think will be difficult which I wonder if you really really want to proceed with:
If the text font is variable at runtime, then it is possible that your fixed width label will never be able to fit the text in it. If the user cannot change the font size, then at least you know the hieght is relatively consistent, but what about the width? It is still possible for some extra wide fonts to go beyond the width of the caption.
I think you are saying that you would like to place a label control on a form and have it resize itself up to a certain width and height? If that is right, what do you wish to do with the excess text - just make it so it cannot be seen (default) or make it so the user can scroll down the label to see what it is?
I might not understand the intent fully, but I think I can help as I have done something similar myself.
I'll see if I can help after you help me to understand your intent better 
Regards
Paul Lewis
-
Jul 27th, 2000, 03:03 AM
#3
Thread Starter
Lively Member
h & w are both fixed..
Paul,
It's the ticker thing again..My label box is of constant size..The labels may only expand if screen resolution is altered and/or the form is docked. I permit the user to select fonts between 8 and 14. However, still with low resolutions the text in the label box may not fit and flood to the next line. What I mean is can I identify the amount of maximum text (characters) that can fit in the current resolution. One idea, which is quite rough though, is I can allow certain character limits for a list of font size, and res. combinations.. And then left(string) the text accordingly..
Any other ideas..?
Kiziltan Yuceil
Freelance Web/VB/VBA Programmer
"It's not what you know it's to whom you consult and with whom you collaborate"
-
Jul 27th, 2000, 03:19 AM
#4
Addicted Member
I tend to work around the standard-sized windows fonts, as that's what the majority of people use. If people insist on using stupidly big default fonts, that's their problem, really.
Visual Basic 6 Enterprise Edition + SP4
-
Jul 27th, 2000, 03:30 PM
#5
Hyperactive Member
Ahhh..
So if I were to tell you a method to determine whether the text you are about to post to the caption is going to be too wide, would that help?
I still don't know what you may wish to do about the oversized text, perhaps reduce the font automatically?
I will post a solution for you after I have finished clearing my inbox b
Cheers
Paul Lewis
-
Jul 27th, 2000, 03:36 PM
#6
So Unbanned
You could used a fixed-width font like courier or an OCR type-face. Then see how many fit and then just do something like:
Label1.caption = Left$(Label1.Caption, 7)
Good luck,
-
Jul 27th, 2000, 03:39 PM
#7
Hyperactive Member
Simple solution
No fancy stuff here, no API calls or anything. Hopefully this provides a springboard for you to use to implement a solution for yourself 
On a form I have Label1, Text1, Command1, PictureBox1
The PictureBox and Label are exactly the same size and font settings. The PictureBox is not visible at runtime.
Code:
Private Sub Command1_Click()
Dim txtWid, txtHgt As Single
Dim myText As String
myText = Text1.Text
txtWid = Picture1.TextWidth(myText)
txtHgt = Picture1.TextHeight(myText)
If txtWid > Label1.Width Or txtHgt > Label1.Height Then
Debug.Print "too big"
Else
Label1.Caption = myText
End If
End Sub
Chances are that if this helps you, the TextWidth / TextHeight were previously unknown to you... If you already knew, then I have probably missed the mark again so sorry in advance 
Cheers
Paul Lewis
-
Jul 27th, 2000, 03:44 PM
#8
So Unbanned
Just though of something,
if only what's on the left part of the label is important then you can use alt+0160 instead of a space, that way it won't wrap.
-
Jul 28th, 2000, 05:21 AM
#9
Thread Starter
Lively Member
Well done, guys!
DigitalError, cool idea about chr(160)! Worked perfect, jus t as I wanted!
Paul, I liked your approach either! I always appreciate to sort out stuff with invisible objects!
Kiziltan Yuceil
Freelance Web/VB/VBA Programmer
"It's not what you know it's to whom you consult and with whom you collaborate"
-
Jul 28th, 2000, 06:41 AM
#10
Thread Starter
Lively Member
Urgent help needed on some other fact!
http://forums.vb-world.net/showthrea...threadid=24342
Could you guys check if you might provide some assistance?
Kiziltan Yuceil
Freelance Web/VB/VBA Programmer
"It's not what you know it's to whom you consult and with whom you collaborate"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|