Solved

Vertically align text box

Posted on 2000-03-07
3
415 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel object stays open 19 70
VBA/SQL - Connect to SQL server and pull data 4 87
Copy a row 12 57
I need help embedding an image as HTML in my vb.net application 3 45
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

948 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

20 Experts available now in Live!

Get 1:1 Help Now