Zarovnání textu tlačítka

Postup:
Založte nový projekt. V deklarační sekci formuláře napište:

'Zarovnávací konstanty
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 
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)

Na formulář přidejte tlačítko a check box. Na událost click checkboxu:

Private Sub Check1_Click()
    Dim tmpValue&
    Dim Align&
    Dim ret&
    If Check1.Value = Checked Then 
        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 
        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

Spusťte aplikaci a zkuste přepínat checkbox.

Zpět

Autor: The Bozena