View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Changing BackColor of ToggleButton produces a muddy grey color

When an ActiveX toggle button is depressed it displays a dithered
combination of white and the backcolor in alternate pixels. I don't know of
any direct way to make it a sold color (picture perhaps).

There are various ways you could simulate a depressed button. One is to use
the brick like autoshape from the "Basic shapes" menu (like a double
rectangle). Add some text and centralise vertically & horizontally

Assign to a macro and do something like

' in a normal module
Sub myToggle()
Dim bOldState As Boolean
Dim nFrClr As Long, nBkClr As Long
Dim sCaller As String
Dim shp As Shape
sCaller = Application.Caller

Set shp = ActiveSheet.Shapes(sCaller)
bOldState = shp.VerticalFlip
shp.Flip msoFlipHorizontal
shp.Flip msoFlipVertical

If bOldState Then
nFrClr = RGB(220, 220, 220)
nBkClr = vbBlack
Else
nFrClr = RGB(255, 0, 0)
nBkClr = vbWhite
End If

shp.Fill.ForeColor.RGB = nFrClr
shp.TextFrame.Characters.Font.Color = nBkClr

If bOldState Then
' code
Else
' code
End If
End Sub


Regards,
Peter T


"IanKR" wrote in message
...
I have a ToggleButton on a worksheet in a project I'm developing for a
cricket scorebook. I'd like it to change colour when pressed. This is my
code:

Private Sub togNoBall_Click()
With togNoBall
'when not pressed
If .Value = False Then
.BackColor = &H8000000F 'grey = default button colour
End If
'when pressed
If .Value = True Then
.BackColor = RGB(255, 0, 0) 'bright red
'[I shall eventually put some other code in here, to fire up
the No Ball Userform]
End If
End With
End Sub

I want it to change to red when clicked, and back to grey when "unclicked"
(or not clicked at all). The problem is, it does change colour, but not to
the bright, solid, vivid red that I'd expect. It changes to a sort of
pink - like if the red is mixed with grey. When it is clicked (and is the
pink/grey colour), and I then click on it again, before it changes back to
grey, but while the click is held down, it does change to the red colour
I'd like it to be, when clicked. A similar thing happens when I use other
colours.

Is this due to some Windows appearance setting on my PC, outside of Excel?

Thanks

Ian