VB Code:
  1. 'Place a command button(Command1) And a check box(Check1) on the form
  2. 'Click checkbox to set the alignment
  3.  
  4. 'Alignment constants
  5. Private Const BS_CENTER& = &H300&
  6. Private Const BS_LEFT& = &H100&
  7. Private Const BS_RIGHT& = &H200&
  8. Private Const BS_TOP& = &H400&
  9. Private Const GWL_STYLE& = (-16)
  10. 'API Calls
  11. Private Declare Function GetWindowLong& Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long)
  12. Private Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
  13.  
  14. Private Sub Check1_Click()
  15.     'Declare Variables
  16.     Dim tmpValue&
  17.     Dim Align&
  18.     Dim ret&
  19.     Dim fAlignment As Long
  20.    
  21.     'Check if the state is checked
  22.     If Check1.Value = Checked Then 'Yes
  23.         fAlignment& = BS_LEFT
  24.         tmpValue& = GetWindowLong&(Command1.hwnd, GWL_STYLE) And Not BS_RIGHT
  25.         ret& = SetWindowLong&(Command1.hwnd, GWL_STYLE, tmpValue& Or fAlignment&)
  26.         Command1.Refresh
  27.     Else 'No
  28.         fAlignment& = BS_CENTER
  29.         tmpValue& = GetWindowLong&(Command1.hwnd, GWL_STYLE) And Not BS_RIGHT Or BS_LEFT
  30.         ret& = SetWindowLong&(Command1.hwnd, GWL_STYLE, tmpValue& Or fAlignment&)
  31.         Command1.Refresh
  32.     End If
  33. End Sub