Solved

Vertically align text box

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

717 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