×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

center text verytically in textbox

center text verytically in textbox

center text verytically in textbox

(OP)
center text vertically in textbox, possible?

now i see
____
ciao

____


i need

___

ciao

_____

RE: center text verytically in textbox

Yes.

RE: center text verytically in textbox

(OP)
tks. Have a tips code?

RE: center text verytically in textbox

Do you think it might be helpful for you to identify the application?

RE: center text verytically in textbox

(OP)
vb6

RE: center text verytically in textbox

In VBA it would be Object.ShapeRange.TextFrame2.VerticalAnchor = msoAnchoMiddle

I'd suspect something similar in VB6.

RE: center text verytically in textbox

?I'd suspect something similar in VB6.

I wouldn't

VB 6 textboxes do not have a vertical alignment property

But you can fake it with a couple of API calls. Note as ever that this is an illustrative idea, NOT a full, production solution

CODE -->

Option Explicit

'Set MultiLine property of the TextBox to True

Private Type RECT
        Left   As Long
        Top   As Long
        Right   As Long
        Bottom   As Long
End Type

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const EM_GETRECT = &HB2
Private Const EM_SETRECTNP = &HB4

Sub VerMiddleText(mText As TextBox)
        If mText.MultiLine = False Then Exit Sub
        Dim rc As RECT
        Dim tmpTop As Long
        Dim tmpBot As Long
        
        SendMessage mText.hwnd, EM_GETRECT, 0, rc
        Set Me.Font = mText.Font
        tmpTop = ((rc.Bottom - rc.Top) - (mText.Parent.TextHeight("H ") \ Screen.TwipsPerPixelY)) \ 2 + 2
        tmpBot = ((rc.Bottom - rc.Top) + (mText.Parent.TextHeight("H ") \ Screen.TwipsPerPixelY)) \ 2 + 2
        rc.Top = tmpTop
        rc.Bottom = tmpBot
        mText.Alignment = vbCenter
        SendMessage mText.hwnd, EM_SETRECTNP, 0&, rc
        mText.Refresh
End Sub

Private Sub Form_Load()
        VerMiddleText Text1
End Sub 



RE: center text verytically in textbox

(OP)
dubt, this code work..
see image.

SI and NO are label....

CODE

Option Explicit
Private Type RECT
        Left   As Long
        Top   As Long
        Right   As Long
        Bottom   As Long
End Type
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const EM_GETRECT = &HB2
Private Const EM_SETRECTNP = &HB4
Private Sub Form_Activate()

    Me.Text1.SetFocus

End Sub
Private Sub Form_Load()

    Call STOP_MOVE(Me.Caption)

    Me.TSCONTRINO.Text = SCONTRINO
    
    VerMiddleText Me.TSCONTRINO

End Sub
Private Sub LSI_Click()

    NOLOAD1 = True
    OK = True
    Unload Me

End Sub
Private Sub LNO_Click()

    NOLOAD1 = True
    OK = False
    Unload Me

End Sub
Sub VerMiddleText(mText As TextBox)
        If mText.MultiLine = False Then Exit Sub
        Dim rc As RECT
        Dim tmpTop As Long
        Dim tmpBot As Long
        
        SendMessage mText.hwnd, EM_GETRECT, 0, rc
        Set Me.Font = mText.Font
        tmpTop = ((rc.Bottom - rc.Top) - (mText.Parent.TextHeight("H ") \ Screen.TwipsPerPixelY)) \ 2 + 2
        tmpBot = ((rc.Bottom - rc.Top) + (mText.Parent.TextHeight("H ") \ Screen.TwipsPerPixelY)) \ 2 + 2
        rc.Top = tmpTop
        rc.Bottom = tmpBot
        mText.Alignment = vbCenter
        SendMessage mText.hwnd, EM_SETRECTNP, 0&, rc
        mText.Refresh
End Sub 

RE: center text verytically in textbox

I suspect that ypu've ignored this key requirement that was a comment I specifically put in the code:

Set MultiLine property of the TextBox to True

RE: center text verytically in textbox

(OP)
SORRY me strongm, i'm distract...

now work perfect!
Tks.


but i can use also for label SI an NO, or i need to use another method

RE: center text verytically in textbox

" i need to use another method" control. Use Command Buttons.

Quote (strongm)

this [code] is an illustrative idea, NOT a full, production solution

"now work perfect!" - not really. Type anything in the text box, hit Enter, type something else, hit Enter.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: center text verytically in textbox

Why even bother with the text vertical alignment of the text box?
You can accomplish that very easy with assigning right Height of the text box:



Actually, between 'too small' and 'just right' there is almost no difference.
And what is nice, you really cannot make the textbox 'too small' because VB will not allow you to...

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close