Re: Change Box Color on CheckBox Control

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance





Then for all practical purposes, you don't need the checkbox functionality
for those mirrored checkboxes, do you? You could just show an image
of a checked box. (That's one way). If that is close to what you need,
you might also just draw the checkboxes on the form as needed. Because
they are not any sort of control, clicking on them has no effect....

For an example, add a Module to a new project and put a checkbox on
the default form. Set the checkbox's Index property to 0 and paste in the
code below to their respective modules. The grey boxes will mirror the
real ones....

HTH
LFS

' [ Form1 code ]
Option Explicit

Private Sub Check1_Click(Index As Integer)
DrawCheckbox Me.hDC, 10, Check1(Index).Top, (Check1(Index).Value = vbChecked)
End Sub

Private Sub Form_Load()
Dim idx As Long
Show
Refresh
ScaleMode = vbPixels
For idx = 0 To 5
If idx Then Load Check1(idx)
Check1(idx).Caption = "ITEM " & idx
Check1(idx).Move 40, idx * 18 + 10
Check1(idx).Visible = True
DrawCheckbox Me.hDC, 10, Check1(idx).Top, False
Next

End Sub



' [ Module1 code ]
Option Explicit

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function DrawFrameControl Lib "user32" ( _
ByVal hDC As Long, _
lpRect As RECT, _
ByVal un1 As Long, _
ByVal un2 As Long) As Long

Private Const DFC_BUTTON As Long = 4
Private Const DFCS_CHECKED As Long = &H400
Private Const DFCS_INACTIVE As Long = &H100

Public Sub DrawCheckbox(ByVal hDC As Long, _
ByVal Left As Long, ByVal Top As Long, _
ByVal Checked As Boolean)
Dim rct As RECT

rct.Left = Left
rct.Top = Top
rct.Right = rct.Left + 30
rct.Bottom = rct.Top + 13

DrawFrameControl hDC, rct, DFC_BUTTON, DFCS_INACTIVE Or (Checked And DFCS_CHECKED)

End Sub




Well, at least I have learned that it is not as trivial as I first
expected it to be. Thanks for everyone's help. I think the idea of
just putting up the image of a checked gray box or an unchecked gray
box might be a good road. I did try to copy and paste in this code,
but all sorts of errors. I am working with VS2005...was this code for
another version?

I agree that changing the color of the text would also work (and be
easy to implement) but it isn't really the look I want.

.



Relevant Pages

  • Re: Click-Ereignis =?iso-8859-1?Q?unterdr=FCcken?=
    ... > mit 1 CheckBox: Check1 ... > Private mInhibitFlag As Boolean ... > Private Sub Check1_Click ...
    (microsoft.public.de.vb)
  • Re: Checkbox-Weite automatisch setzen
    ... Public Sub SetProperCheckBoxWidth ... (ByVal uCheckBox As CheckBox) ... Private WithEvents CheckBox1 As CheckBox ... Private mCounter As Integer ...
    (microsoft.public.de.vb)
  • RE: Calling a sub on another worksheet
    ... Try the following with double quotes and also note full name of sub ... I am trying to use a checkbox to show or hide an additional worksheet. ... part is easy - but what I am also trying to do is call a subroutine (Private ... Dim RemSection As Long ...
    (microsoft.public.excel.programming)
  • Re: Using Checkbox Values
    ... While it's true the even code is designated Private by default, ... I have created a checkbox on Sheet1, then the following sub (in ... Module1) produces different output dependent on whether the checkbox ... When I create a checkbox (using the control toolbox), ...
    (microsoft.public.excel.programming)
  • Re: Collection disappearing at run time
    ... the Tab so that it doesn't take any arguments. ... > Private _tabHeight As New Unit ... > Public Overrides Property HeightAs Unit ... > Protected Overrides Sub OnInit ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)