Results 1 to 4 of 4

Thread: [RESOLVED] Coping with different length strings

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Resolved [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.

  2. #2
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    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.

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    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:
    1. 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
    2.  
    3. Private Type RECT
    4.     Left As Long
    5.     Top As Long
    6.     Right As Long
    7.     Bottom As Long
    8. End Type
    9.  
    10. Private Const DT_MODIFYSTRING As Long = &H10000
    11. Private Const DT_END_ELLIPSIS As Long = &H8000&
    12. Private Const DT_PATH_ELLIPSIS As Long = &H4000&
    13. Public Function EllipseText(ByVal sTxt As String, ByVal nMaxWidth As Long, frm As Form, Optional ByVal IsPath As Boolean) As String
    14.     Dim nFlags As Long
    15.     Dim r As RECT
    16.    
    17.     nFlags = DT_MODIFYSTRING + _
    18.              IIf(IsPath, DT_PATH_ELLIPSIS, DT_END_ELLIPSIS)
    19.     r.Right = frm.ScaleX(nMaxWidth, frm.ScaleMode, vbPixels)
    20.     Call DrawText(frm.hDC, sTxt, Len(sTxt), r, nFlags)
    21.     EllipseText = sTxt
    22. End Function

    usage
    VB Code:
    1. Label1.ToolTipText = NewKey
    2.     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"

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    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
  •  



Click Here to Expand Forum to Full Width