"Tim Rude" <
timrude...@nospam.hotmail.com> wrote in message
news:k6opf6$2uc$1...@dont-email.me...
> "Mike Williams" <Mi...@WhiskyAndCoke.com> wrote in message
> news:k6odav$m52$1...@dont-email.me...
>> Yes, it does exactly what the OP wants.
>> Mike
>
> Well, I must be doing something wrong then because I can't get
> it to work. Here's my sample code for a Form with a checkbox
> (Check1) and two buttons (Command1(0) and Command1(1))
> in a control array.
Add a third CommandButton to your existing Form (Command1(2)) and use the
following code instead of the code you are currently using (it uses the same
code as you have already got for setting the size and caption of the
CheckBox, but the rest is different). While you're at it, set the CheckBox's
BackColor to cyan (or some other colour which contrasts with the BackColor
of your Form) so that you can see more clearly see what happens with respect
to the positioning of the text within the CheckBox.
Mike
Option Explicit
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_STYLE As Long = (-16)
Private Const BS_TOP As Long = &H400&
Private Const BS_BOTTOM As Long = &H800&
Private Const BS_VCENTER As Long = &HC00&
Private Sub Form_Load()
With Check1
.Height = 1575
.Width = 1995
.Caption = "This checkbox has a very long caption that " _
& "wraps to multiple lines and does ugly things " _
& "with the box alignment."
End With
Command1(0).Caption = "BS_TOP"
Command1(1).Caption = "BS_BOTTOM"
Command1(2).Caption = "BS_VCENTER"
End Sub
Private Sub Command1_Click(Index As Integer)
Dim style As Long
style = GetWindowLong(Check1.hwnd, GWL_STYLE)
Select Case Index
Case 0
SetWindowLong Check1.hwnd, GWL_STYLE, _
(style And Not BS_BOTTOM) Or BS_TOP
Case 1
SetWindowLong Check1.hwnd, GWL_STYLE, _
(style And Not BS_TOP) Or BS_BOTTOM
Case 2
SetWindowLong Check1.hwnd, GWL_STYLE, _
style Or BS_VCENTER
End Select
Check1.Refresh
End Sub