Click here to Skip to main content
14,768,153 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
So i know how to change the colour of a button, but is it possible to change the colour of the button when the button is busy, as it normally is a shade of light blue

I have always wondered about this :) and would love some help please
Posted
Updated 13-May-13 9:02am
v3
Comments
johannesnestler 13-May-13 14:04pm
   
The answer is yes - but hard to give you an example because you didn't say which technology you are using (ASP.NET, Forms, WPF., Silverlight). At the end it comes down to reacting to some kind of MouseUp and MouseDown events - I assume with "busy" you mean "holding down"...
[no name] 13-May-13 14:16pm
   
i use c sharp.net 'microsoft visual c sharp express' also i mean when the button is processed there is a lot of code so the button shows as a light blue because it is working through it all.

I dont want to know about how to simplify the code, but just want to know about changing the colour please :)
johannesnestler 14-May-13 4:08am
   
after reading all the comments your answers and solutions here, I'm still confused what you mean with busy? I sum up what I understand: You are using WinForms and a System.Windows.Forms.Button, you want to change the default button theming controled by Windows (theme) to something else. In your Images you showed a button - which is unpressed and blue because it's the "Default Button" of the dialog window. So you just want to "turn of theming"? or do you want to change the Color for a special "state" of the button (Enabled, Default, MouseDown, MouseHover, ...)?
[no name] 13-May-13 14:07pm
   
i use c sharp.net 'microsoft visual c sharp express' also i mean when the button is processed there is a lot of code so the button shows as a light blue because it is working through it all.

I dont want to know about how to simplify the code, but just want to know about changing the colour please :)
ZurdoDev 13-May-13 14:15pm
   
You need to reply to the comment so that the user is notified, instead of adding a new comment to your own question.
[no name] 13-May-13 14:21pm
   
ok any suggestions then please
Maciej Los 13-May-13 14:50pm
   
WinForms, WebControls, WPF?
[no name] 13-May-13 15:40pm
   
win forms
Sergey Alexandrovich Kryukov 13-May-13 16:40pm
   
When UI is involved, you always need to tag UI library or application type you are using. What is the full name of your "Button" class?
—SA

A button is never "busy" so your question is confusing people.

You have a problem. The UI thread will be tied up by your "lot of code" that's running, so changing the color of the button won't do anything until AFTER your long running code because you've tied up the UI thread and it can't paint the button in the new color.

You have to move the long running code to a seperate thread so the UI thread can repaint the button. There are tons of examples on the web on how to do that, but which technology you chose pretty much depends on what you're long running code is doing and if you want to support cancellation and whatnot.

Google for "C# Tasks" or "C# Backgroundworker" for some examples of doing it the "easy" way.
   
Comments
Maciej Los 13-May-13 15:07pm
   
Good point!
+5
[no name] 13-May-13 15:21pm
   
i mean when the colour of the button goes like this

http://www.dontbreakthebuild.com/images/background_worker.png
sja63 13-May-13 15:36pm
   
Hi,

I guess your button is light blue, not because it is busy,
but it is the default button ?
Dave Kreskowiak 13-May-13 15:59pm
   
It's blue because the mouse is hovering over it. There is no such thing as a "busy" button.
[no name] 13-May-13 15:18pm
   
i mean when the colour of the button goes like this

http://www.dontbreakthebuild.com/images/background_worker.png
Sergey Alexandrovich Kryukov 13-May-13 16:40pm
   
5ed. I added one more answer, please see.
—SA
Instead of changing color, you should disable the button. Use the property IsEnabled or Enabled — it depends on the exact button type you did not bother to specify. Different UI libraries have different classes under the simple name "Button". When UI is involved, you always need to tag UI library or application type you are using.

—SA
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900