Solved

Vertically align text box

Posted on 2000-03-07
3
401 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
3 Comments
 
LVL 1

Accepted Solution

by:
ocpgmbh earned 100 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now