HighTechTalks DotNet Forums  

Change the color of a button

Dotnet Academic General Discussions microsoft.public.dotnet.academic


Discuss Change the color of a button in the Dotnet Academic General Discussions forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Marium A.
 
Posts: n/a

Default Change the color of a button - 07-14-2003 , 12:11 PM






In my program, I have a button that allows the user to
change the color of an object by bringing up the standard
color selection box. I want this button to reflect the
color selected. How may I change the color of the button?

I appreciate any help!

Reply With Quote
  #2  
Old   
Alfred C Thompson II
 
Posts: n/a

Default Re: Change the color of a button - 07-14-2003 , 07:19 PM






OK really you can't do this as easily as you'd like. The color of a button
is a system wide value. Change one button and you change them all. This is
by design to make windows programs look consistatly the same. What you can
do is use another object as a button. In other words you can use a picture
box and have it respond to clicks. What many of my students have done is to
create several images and use them in a picture box. One image for up and
one for down. Change them on the mouse down and up events. You can do all
sorts of variations of this to siimulate buttons that ahve what ever
features you want.

"Marium A." <examiners (AT) yahoo (DOT) com> wrote

Quote:
In my program, I have a button that allows the user to
change the color of an object by bringing up the standard
color selection box. I want this button to reflect the
color selected. How may I change the color of the button?

I appreciate any help!



Reply With Quote
  #3  
Old   
Jay B. Harlow [MVP - Outlook]
 
Posts: n/a

Default Re: Change the color of a button - 07-15-2003 , 02:59 PM



Marium,
To qualify what Alfred & Peter stated.

If you set the Button's FlatStyle property to System, you will not be able
to change the BackColor property of the button, as the System will control
it. Just as Alfred stated.

If you set the Button's FlatStyle to Standard, Flat, or Sunken, you will be
able to change the BackColor property of the Button. Just as Peter stated.

You can change the BackColor with FlatStyle.System, its just the button will
ignore you.

You need to use FlatStyle.System if you want to enable Windows XP themes on
your form, via EnableVisualStyles or manifest file.

Hope this helps
Jay

"Marium A." <examiners (AT) yahoo (DOT) com> wrote

Quote:
In my program, I have a button that allows the user to
change the color of an object by bringing up the standard
color selection box. I want this button to reflect the
color selected. How may I change the color of the button?

I appreciate any help!



Reply With Quote
  #4  
Old   
Peter van der Goes
 
Posts: n/a

Default Re: Change the color of a button - 07-16-2003 , 08:10 AM




"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow (AT) email (DOT) msn.com> wrote

Quote:
Marium,
To qualify what Alfred & Peter stated.

If you set the Button's FlatStyle property to System, you will not be able
to change the BackColor property of the button, as the System will control
it. Just as Alfred stated.

If you set the Button's FlatStyle to Standard, Flat, or Sunken, you will
be
able to change the BackColor property of the Button. Just as Peter stated.

You can change the BackColor with FlatStyle.System, its just the button
will
ignore you.

You need to use FlatStyle.System if you want to enable Windows XP themes
on
your form, via EnableVisualStyles or manifest file.

Hope this helps
Jay

Thanks, Jay!
It certainly helps me, as I was not aware of this effect of the FlatStyle
property setting.





Reply With Quote
  #5  
Old   
Joseph
 
Posts: n/a

Default Change the color of a button - 07-17-2003 , 02:01 AM




..BackColor property set to a new color.
Eg.

butAdd.BackColor = Color.Red;
Thanks,
Joseph.



Quote:
-----Original Message-----
In my program, I have a button that allows the user to
change the color of an object by bringing up the standard
color selection box. I want this button to reflect the
color selected. How may I change the color of the button?

I appreciate any help!
.


Reply With Quote
  #6  
Old   
Marium A.
 
Posts: n/a

Default Change the color of a button - 07-17-2003 , 01:08 PM



Hi, Thank you so much for your answers. I'm using C++. I
guess the controls are a bit different from VB, because
CButton does not have a .BackColor option (or anything
else like it). I'm now using the custom control option to
create a CStatic control, but it seems like there's no
function to specify its color either.

Marium

Reply With Quote
  #7  
Old   
Andrew Downum
 
Posts: n/a

Default Change the color of a button - 07-17-2003 , 06:02 PM



CButton is an MFC class (the reason that you are getting
confusing answers is that you posted in a .NET forum).

To get a custom-colored button in MFC you will have to
owner-draw it. Basically instead of leaving it up to the
system to draw the button for you, you will do it
yourself. Relax, it's not as hard as it sounds.

Basically you will just need to set the BS_OWNERDRAW style
(do this in your call to Create), and then override
DrawItem. There are a lot of utility methods that are
available to you that will draw whichever parts of the
button that you don't want to override, check out this
example for some pointers in the right direction:
http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/wcemfc/htm/cbutton_4.asp

(in the future, MFC questions would be better posted in
the vc.mfc newsgroup)

~ Andrew
Quote:
-----Original Message-----
Hi, Thank you so much for your answers. I'm using C++. I
guess the controls are a bit different from VB, because
CButton does not have a .BackColor option (or anything
else like it). I'm now using the custom control option to
create a CStatic control, but it seems like there's no
function to specify its color either.

Marium
.


Reply With Quote
  #8  
Old   
Peter van der Goes
 
Posts: n/a

Default Re: Change the color of a button - 07-18-2003 , 12:01 AM




"Marium A." <examiners (AT) yahoo (DOT) com> wrote

Quote:
Hi, Thank you so much for your answers. I'm using C++. I
guess the controls are a bit different from VB, because
CButton does not have a .BackColor option (or anything
else like it). I'm now using the custom control option to
create a CStatic control, but it seems like there's no
function to specify its color either.

Marium
I'm glad we got that clarified, and that you've received a good answer from
Andrew. FWIW, it's not a C++ vs. VB difference, but a MFC vs. .NET framework
difference. The procedure I described can be done with equal ease in .NET
VB, C# or C++ (in the .NET 2003 Windows Form project template).




Reply With Quote
  #9  
Old   
Marium A.
 
Posts: n/a

Default Re: Change the color of a button - 07-26-2003 , 04:26 PM



Thank you so much! And I will post in MFC in the future.
Quote:
-----Original Message-----

"Marium A." <examiners (AT) yahoo (DOT) com> wrote in message
news:029301c34c86$1d06a810$a101280a (AT) phx (DOT) gbl...
Hi, Thank you so much for your answers. I'm using C++.
I
guess the controls are a bit different from VB, because
CButton does not have a .BackColor option (or anything
else like it). I'm now using the custom control option
to
create a CStatic control, but it seems like there's no
function to specify its color either.

Marium

I'm glad we got that clarified, and that you've received
a good answer from
Andrew. FWIW, it's not a C++ vs. VB difference, but a MFC
vs. .NET framework
difference. The procedure I described can be done with
equal ease in .NET
VB, C# or C++ (in the .NET 2003 Windows Form project
template).


.


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.