Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Checkbox vertical alignment

82 views
Skip to first unread message

Tim Rude

unread,
Oct 29, 2012, 10:03:50 PM10/29/12
to
Is there an easy way (maybe a SendMessage call) to make the box of a
standard VB6 checkbox align with the top line of a multiline caption?

I want

[ ] This is a multiple line
caption for this checkbox
with the box at the top

instead of

This is a multiple line
[ ] caption for this checkbox
with the box in the middle

Please don't suggest using a Label control for the caption, since that
results in losing the dotted outline around the caption when the
checkbox has the focus.

--
Tim Rude

tim...@NOSPAM.hotmail.com
(remove NOSPAM. for correct email address)


Deanna Earley

unread,
Oct 30, 2012, 6:34:35 AM10/30/12
to
On 30/10/2012 02:03, Tim Rude wrote:
> Is there an easy way (maybe a SendMessage call) to make the box of a
> standard VB6 checkbox align with the top line of a multiline caption?

I can't see any message or style that does this.
You could try the BS_BOTTOM and BS_TOP styles that claim to align text
at the bottom and top of the button. It may have a similar effect for
check boxes.

--
Deanna Earley (dee.e...@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored. Please reply to the
group.)

Mike Williams

unread,
Oct 30, 2012, 7:23:18 AM10/30/12
to
"Deanna Earley" <dee.e...@icode.co.uk> wrote in message
news:k6oafp$7aj$1...@speranza.aioe.org...
> On 30/10/2012 02:03, Tim Rude wrote:
>> Is there an easy way (maybe a SendMessage call) to make the box of a
>> standard VB6 checkbox align with the top line of a multiline caption?
>
> I can't see any message or style that does this.
> You could try the BS_BOTTOM and BS_TOP styles that
> claim to align text at the bottom and top of the button. It may
> have a similar effect for check boxes.

Yes, it does exactly what the OP wants.

Mike



Tim Rude

unread,
Oct 30, 2012, 10:50:13 AM10/30/12
to
"Mike Williams" <Mi...@WhiskyAndCoke.com> wrote in message
news:k6odav$m52$1...@dont-email.me...
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. What am I missing?

Option Explicit

Private Declare Function SendMessage _
Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long

Private Const BS_AUTOCHECKBOX = &H3&
Private Const BS_TOP = &H400&
Private Const BS_BOTTOM = &H800&
Private Const BM_SETSTYLE = &HF4&

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"
End Sub

Private Sub Command1_Click(Index As Integer)
Dim BS As Long
Select Case Index
Case 0
BS = BS_TOP Or BS_AUTOCHECKBOX
Case 1
BS = BS_BOTTOM Or BS_AUTOCHECKBOX
End Select
SendMessage Check1.hwnd, BM_SETSTYLE, BS, 1&
End Sub

Mike Williams

unread,
Oct 30, 2012, 11:27:32 AM10/30/12
to

"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



Tim Rude

unread,
Oct 30, 2012, 12:39:28 PM10/30/12
to
"Mike Williams" <Mi...@WhiskyAndCoke.com> wrote in message
news:k6orks$ior$1...@dont-email.me...
Excellent! That is exactly the result I was looking for. :)

FWIW, before posting the original question I searched quite a bit and was
unable to find anywhere that this was addressed.

Thank you!

0 new messages