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

Checkbox Pressed Color

5 views
Skip to first unread message

Aoli

unread,
Feb 10, 2022, 12:50:08 PM2/10/22
to
Why MS did this? I wish they had not.

Checkbox Style Graphical

make background color green when pressed in code.

press the checkbox and you get light green as in green hatched with white.

I want solid green not hatched with white. i.e. good color rendering.

I found how to set the foreground color on a command button but is there
a way to set the true background color on a depressed checkbox.

SendMessage anyone ?

I need another tool in my toolbox.

Makes me depressed. LOL.

Aoli

unread,
Feb 10, 2022, 1:45:50 PM2/10/22
to
Here is a terrible solution that works perfectly.
Must be a better easier way ???

PictureBox, picChkTest on top of a
CheckBox, chkTest

chkTest Style set to Graphical

picChkTest.Appearance set to Flat
picChkTest.Border set to None

' =============== SAMPLE CODE =========================

Private Const WM_KILLFOCUS As Long = &H8

Private Sub picChkTest_Click()

Dim sPrint As String

picChkTest.Move chkTest.Left + 10, chkTest.Top + 10, chkTest.Width
- 20, chkTest.Height - 20
chkTest.Value = IIf(chkTest.Value = vbChecked, vbUnchecked, vbChecked)
picChkTest.BackColor = IIf(chkTest.Value = vbChecked, eClrGrn,
vbButtonFace)
sPrint = IIf(chkTest.Value = vbChecked, "PRESSED", "UNPRESSED")
picChkTest.CurrentX = (picChkTest.Width - TextWidth(sPrint)) \ 2
picChkTest.CurrentY = (picChkTest.Height - TextHeight(sPrint)) \ 2
picChkTest.Print sPrint;

End Sub

Private Sub chkTest_MouseUp(Button As Integer, Shift As Integer, X As
Single, Y As Single)

If chkTest.Value = vbChecked Then
FocusNot chkTest ' sets focus to NOT focus, focus box hater

Else
chkTest.UseMaskColor = False

End If

End Sub

Public Sub FocusNot(oControl As Control)

On Error Resume Next

SendMessage oControl.hwnd, WM_KILLFOCUS, 0&, ByVal 0&

End Sub ' FocusNot


Mayayana

unread,
Feb 10, 2022, 5:26:10 PM2/10/22
to
"Aoli" <Ao...@Aoli.com> wrote |
| Checkbox Style Graphical
|
| make background color green when pressed in code.

I'm not sure if this is what you want, and you didn't
show your code, but this works for me:

Private Sub Check1_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Check1.BackColor = 65280 '-- that's bright green. this is grass green:
32768
End Sub

Private Sub Check1_MouseUp(Button As Integer, Shift As Integer, X As Single,
Y As Single)
Check1.BackColor = vbButtonFace
End Sub

The only trouble is that people don't hold it down, so
you never see the color change. If you just want it
to change semi-permanently you could track it:

If backcolor = x then... else...


Larry Serflaten

unread,
Feb 11, 2022, 1:04:06 PM2/11/22
to
Aoli wrote:

> Checkbox Style Graphical
> make background color green when pressed in code.
> press the checkbox and you get light green as in green hatched with white.
> I want solid green not hatched with white. i.e. good color rendering.

> I need another tool in my toolbox.

If you are going with a non-conventional control type, why not make it
easy on yourself? Place a transparent Label control over a Shape
control and use the Shape control to show the colors. Ex:

Private Sub Form_Load()
'Label1.Appearance = 0 ' set in property box
Label1.BackStyle = vbTransparent
Shape1.FillStyle = 0
Shape1.FillColor = vbButtonFace
End Sub

Private Sub Label1_Click()
If (Shape1.FillColor = vbButtonFace) Then
Shape1.FillColor = RGB(20, 200, 0)
Else
Shape1.FillColor = vbButtonFace
End If
End Sub


... Done! :-)
LFS


0 new messages