Results 1 to 5 of 5

Thread: resizing label horizontally?

  1. #1

    Thread Starter
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306

    Talking resizing label horizontally?

    just wanna do what the subject says really :]

    given a label, a text string and a specific width, I need to size the label in height accordingly ....

    anyone?

  2. #2
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    VB Code:
    1. Private Sub Command1_Click()
    2.     Label1.Width = 4000 ' assign a custom width
    3. End Sub
    4.  
    5. Private Sub Command2_Click()
    6.     Label1.FontSize = 25
    7.     Label1.FontBold = True
    8. 'automatic assigning of the label's properties to make the label's caption viewable
    9.     Label1.AutoSize = True
    10. End Sub
    11.  
    12. Private Sub Form_Load()
    13. Label1.Left = Me.ScaleLeft
    14. Label1.Top = Me.ScaleTop
    15. Label1.Caption = "this is a Loooooooooooong string"
    16. End Sub

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

  3. #3

    Thread Starter
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306
    need to add label1.wordwrap = true but yea that sorta does the trick

    tx

  4. #4
    Hyperactive Member
    Join Date
    May 2002
    Location
    Chicago
    Posts
    271
    If you can afford to use a multiline textbox this code works fine
    using the API to get the line count.
    Code:
    Private Declare Function SendMessageAsLong Lib "user32" Alias "SendMessageA" _
      (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Const EM_GETLINECOUNT = 186
    
    Private Sub Form_Load()
      Label1.AutoSize = True
      Text1.BorderStyle = 0
      Text1.BackColor = vbYellow
      Text1.Width = 1500
      Text1 = "This is a test to show how the api may be used to increase the height of a multiline text box based on the number of lines in the text box."
    End Sub
    
    Private Sub Text1_Change()
      Dim lCount As Long
      Text1.SelStart = 0 'prevents top line from being cut-off
      'use API function to get the line count of Text1
      lCount = SendMessageAsLong(Text1.hWnd, EM_GETLINECOUNT, 0, 0)
      'multiply line count by line height and add 60 for border
      Text1.Height = (TextHeight(Text1.Text) * lCount) + 60
      Text1.SelStart = Len(Text1.Text) + 1 'ready for next character
    End Sub
    Sometimes what you're looking for is exactly where you left it.

  5. #5

    Thread Starter
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306
    that will be v.useful in a diff part of my proggy, nice 1


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