|
-
Jul 2nd, 2002, 03:31 AM
#1
Thread Starter
Hyperactive Member
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?
-
Jul 2nd, 2002, 03:56 AM
#2
Frenzied Member
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
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Jul 2nd, 2002, 04:00 AM
#3
Thread Starter
Hyperactive Member
need to add label1.wordwrap = true but yea that sorta does the trick
tx
-
Jul 2nd, 2002, 04:19 AM
#4
Hyperactive Member
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.
-
Jul 2nd, 2002, 04:22 AM
#5
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|