?
Solved

Vertically align text box

Posted on 2000-03-07
3
Medium Priority
?
518 Views
Last Modified: 2010-05-02
I know when I program in Visual C++ I can vertically align the text in a text box... is it possible from VB?
0
Comment
Question by:taplin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 1

Accepted Solution

by:
ocpgmbh earned 400 total points
ID: 2592298
Directly from VB you can't use a vertical alignment, but you can use the DrawText API call.

For a complete example send an email to mshelp@microsoft.com with in the subject line "Q154517" without quotes.

Good work.

0
 
LVL 9

Expert Comment

by:Dalin
ID: 2592405
ocpgmbh is right,  VB Text box can't directly align vertically.

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, "")
0
 
LVL 2

Author Comment

by:taplin
ID: 2593311
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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question