ButtonAlignmentAPI




Option Explicit
'Alignment constants

Private Const BS_CENTER& = &H300&
Private Const BS_LEFT& = &H100&
Private Const BS_RIGHT& = &H200&
Private Const BS_TOP& = &H400&
Private Const GWL_STYLE& = (-16)
'API Calls

Private Declare Function GetWindowLong& Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long)
Private Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
Private Sub Check1_Click()
'Declare Variables

Dim tmpValue&
Dim Align&
Dim ret&
Dim fAlignment As Long

'Check if the state is checked

If Check1.Value = Checked Then 'Yes
fAlignment& = BS_LEFT
tmpValue& = GetWindowLong&(Command1.hwnd, GWL_STYLE) And Not BS_RIGHT
ret& = SetWindowLong&(Command1.hwnd, GWL_STYLE, tmpValue& Or fAlignment&)
Command1.Refresh
Else 'No
fAlignment& = BS_CENTER
tmpValue& = GetWindowLong&(Command1.hwnd, GWL_STYLE) And Not BS_RIGHT Or BS_LEFT
ret& = SetWindowLong&(Command1.hwnd, GWL_STYLE, tmpValue& Or fAlignment&)
Command1.Refresh
End If
End Sub

Selecting the CheckBox will toggle the alignment
of the text in the button










( buttonalignmentapi.html )- by Paolo Puglisi - Modifica del 17/12/2023