|
-
Feb 7th, 2007, 01:29 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Coping with different length strings
What is the best way to cope with putting things on forms that might have widely different lengths.
For example, I have a form that has a series of labels along the top with descriptions next to them.
One of the label's captions is 'Location'. The descriptive text that goes next to it might say 'The Green Man' or it might say 'Behind Warehouse 3 on the Southern Industrial Estate'.
I have limited space. How can I let readers see all the text? I don't really want to use text boxes if I can help it but, if I must ...
I guess I can set the textbox to be flat etc so it doesn't look as if it is there ... but is there a control I can use that will only get scroll bars if the content is too big.
Thanks for any help.
-
Feb 7th, 2007, 01:46 PM
#2
Frenzied Member
Re: Coping with different length strings
I use textboxes in the way you describe for labels on occasion when faced with a situation similar to yours.
Just remember to set the TabStop to False and I usually put SendKeys "{tab}" in the Gotfocus event to prevent a blinking cursor from ever showing up.
Beantown Boy
Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
-
Feb 7th, 2007, 01:46 PM
#3
Re: Coping with different length strings
you can use a textbox - with horz scrollbar.. make the bg color of it the same as the form.. remove the border.. and set Locked = true
OR
set the tooltip of your label to the same thing as the value.
then change the caption to "whatever goes here....." showin there is more
code to "clip text"
set your form to scalemode Pixels (if you leave it twips you'll just have to make the number higher)
VB Code:
Private Declare Function DrawText Lib "user32.dll" Alias "DrawTextA" (ByVal hDC As Long, ByVal lpStr As String, ByVal nCount As Long, ByRef lpRect As RECT, ByVal wFormat As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Const DT_MODIFYSTRING As Long = &H10000
Private Const DT_END_ELLIPSIS As Long = &H8000&
Private Const DT_PATH_ELLIPSIS As Long = &H4000&
Public Function EllipseText(ByVal sTxt As String, ByVal nMaxWidth As Long, frm As Form, Optional ByVal IsPath As Boolean) As String
Dim nFlags As Long
Dim r As RECT
nFlags = DT_MODIFYSTRING + _
IIf(IsPath, DT_PATH_ELLIPSIS, DT_END_ELLIPSIS)
r.Right = frm.ScaleX(nMaxWidth, frm.ScaleMode, vbPixels)
Call DrawText(frm.hDC, sTxt, Len(sTxt), r, nFlags)
EllipseText = sTxt
End Function
usage
VB Code:
Label1.ToolTipText = NewKey
Label1.Caption = EllipseText(NewKey, 50, Me)
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Feb 15th, 2007, 06:03 AM
#4
Thread Starter
Fanatic Member
Re: Coping with different length strings
Thanks very much for your replies.
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
|