taplin
asked on
Vertically align text box
I know when I program in Visual C++ I can vertically align the text in a text box... is it possible from VB?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you both very much for your responses... I am going to accept the answer, as it works very well for what I need to do... I appreciate the information about anything above the text, though Dalin.
Your solution, Dalin, does not do what I wanted, though.
Your solution, Dalin, does not do what I wanted, though.
Draw text is a good alternative. However, If yiu have something over the text, it will be gone.
Another possible way is to do a little workaround. See if it works for you.
1. Set the textbox's multiline property to True.
2. Set alignment to Left or right or center,
3. In form load add the code
Private Sub Form_Load()
Dim lString As String
Dim i As Integer
If Len(Text1.Text) > 0 Then
For i = 1 To Len(Text1.Text)
lString = lString & Mid(Text1.Text, i, 1) & vbCrLf
Next i
Text1.Text = lString
End If
End Sub
In the Text's Change event, add:
Private Sub Text1_Change()
Dim lLastone As String
Dim lString As String
lString = Left(Text1.Text, Len(Text1.Text) - 1)
If Right(lString, 2) = vbCrLf Then Exit Sub
lLastone = Right(Text1.Text, 1)
lString = lString & vbCrLf & lLastOne
Text1.Text = lString
End Sub
Now your text has VBCRLF in it. When you need it somewhere, strip out the VBCRLF by:
ActualText = Replace(Text1.Text, vbCRLF, "")