Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Changing BackColor of ToggleButton produces a muddy grey color

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Changing BackColor of ToggleButton produces a muddy grey color

Many thanks, Peter, this works well. Interestingly, until I added the button
text, a message box titled "Microsoft Visual Basic" appeared every time I
clicked on the button, with just 400 on it! There was an OK button and a
Help button, but the Help button didn't do anything when I clicked it. But
when I added the text (and after I deleted the text), this no longer
appeared.

Ian

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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Changing BackColor of ToggleButton produces a muddy grey color

Interestingly, until I added the button text, a message box titled
"Microsoft Visual Basic" appeared every time I clicked on the button, with
just 400 on it! There was an OK button and a Help button, but the Help
button didn't do anything when I clicked it. But when I added the text
(and after I deleted the text), this no longer appeared.


Just twigged why (very slow!). Of course, the code changes text colour, and
if there's no text... But it's an unusual VB error message, as it doesn't
halt the code and go into debug mode. That's what confused me.

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

For me, if the AutoShape does not have a TextFrame I get error 1004 unable
to set the color property of the font class. I tested in XL2003 and some
earlier versions. Which version are you using.

BTW it's the lack of a textframe rather than no text that trigger the
anticipated error, at least for me.

Small point of style I forgot to mention last time, to make the 'Bevel'
autoshape look more like a button format with 'no line'.

Regards,
Peter T


"Peter T" <peter_t@discussions wrote in message
...
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








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Changing BackColor of ToggleButton produces a muddy grey color

Thanks. I'm on XL 2003, fully-patched.

"Peter T" <peter_t@discussions wrote in message
...
For me, if the AutoShape does not have a TextFrame I get error 1004 unable
to set the color property of the font class. I tested in XL2003 and some
earlier versions. Which version are you using.

BTW it's the lack of a textframe rather than no text that trigger the
anticipated error, at least for me.

Small point of style I forgot to mention last time, to make the 'Bevel'
autoshape look more like a button format with 'no line'.

Regards,
Peter T


"Peter T" <peter_t@discussions wrote in message
...
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







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text colour keeps changing to grey SarahM Excel Discussion (Misc queries) 0 March 12th 10 12:26 PM
Changing the backcolor of a cell when data is added OldPoplarPete Excel Discussion (Misc queries) 1 February 18th 10 09:50 PM
Changing BackColor on Command Buttons? RBee Excel Discussion (Misc queries) 1 August 30th 06 02:32 AM
Grey Color pcw[_2_] Excel Programming 2 June 24th 04 06:07 PM
Changing backcolor of commandbutton scottnshelly[_21_] Excel Programming 2 April 22nd 04 11:27 PM


All times are GMT +1. The time now is 05:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"