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?
Printable View
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?
VB Code:
Private Sub Command1_Click() Label1.Width = 4000 ' assign a custom width End Sub Private Sub Command2_Click() Label1.FontSize = 25 Label1.FontBold = True 'automatic assigning of the label's properties to make the label's caption viewable Label1.AutoSize = True End Sub Private Sub Form_Load() Label1.Left = Me.ScaleLeft Label1.Top = Me.ScaleTop Label1.Caption = "this is a Loooooooooooong string" End Sub
need to add label1.wordwrap = true but yea that sorta does the trick
tx :D
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
that will be v.useful in a diff part of my proggy, nice 1
:D