CodeItBetter Programming Another VB Programming Blog

How to align Caption on Command Button

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'Controls - How to align Caption on Command Button

Option Explicit
 
'Add a Command Button to your form.

Public Const A_CENTER = &H300&
Public Const A_TOP = &H400&
Public Const A_TOPLEFT = &H500&
Public Const A_TOPRIGHT = &H600&
Public Const A_BOTTOM = &H800&
Public Const A_BOTTOMLEFT = &H900&
Public Const A_BOTTOMRIGHT = &HA00&
Public Const A_LEFT = &H100&
Public Const A_RIGHT = &H200&
Public Const GWL_STYLE& = (-16)
Declare Function GetWindowLong& Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, _
    ByVal nIndex As Long)
Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, _
    ByVal nIndex As Long, ByVal dwNewLong As Long)
 
Private Sub Command1_Click()
    Dim tmpValue&, Align&, ret&
    'This will align the caption to top.
    fAlignment& = A_TOP
    tmpValue& = GetWindowLong&(Command1.hwnd, GWL_STYLE) And Not BS_RIGHT
    ret& = SetWindowLong&(Command1.hwnd, GWL_STYLE, tmpValue& Or fAlignment&)
    Command1.Refresh
End Sub
Filed under: Controls Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.