Click to See Complete Forum and Search --> : How to change highlight color on button click in C#


bharusri
March 20th, 2010, 03:00 PM
Hi folks,

Can anyone please help me in changing the highlight color of a button when clicked. By default when I click on a button its displaying black color. I want to change it to something else. Please let me know how to do that.

Any help is appreciated.

Thank you

JonnyPoet
March 21st, 2010, 04:01 AM
Try this
private void button1_MouseHover(object sender, EventArgs e) {
// when we hoover the button we get this
button1.BackColor = Color.LightGreen;
}
private void button1_MouseLeave(object sender, EventArgs e) {
// when we again leave the button we get back original color
button1.BackColor = Color.Aqua;
}
private void Form1_Load(object sender, EventArgs e) {
// Lets start with this color
button1.BackColor = Color.Aqua;
}

bharusri
March 22nd, 2010, 11:33 AM
Hi Jonny,

Thank you so much for the reply. I will try it and let you know.

I have 6 buttons on my form so do I need to repeat these steps for each button ? Is there any other alternative ?

Thank you once again

Arjay
March 22nd, 2010, 05:58 PM
Hi Jonny,

Thank you so much for the reply. I will try it and let you know.

I have 6 buttons on my form so do I need to repeat these steps for each button ? Is there any other alternative ?

Thank you once againYeah. Just wire up the same event handlers to each button.

BigEd781
March 22nd, 2010, 06:17 PM
Or just make your own button class if this is going to be the theme of your app.

bharusri
March 22nd, 2010, 10:01 PM
I don't find mousehover event under button. But when I copy and paste the code I don't get any error and mousehover event doesn't fire. I am using a student version of Visual Studio. Will there be any limitations because of that. Please let me know.

Thank you so much for the help. I appreciate it.

JonnyPoet
March 23rd, 2010, 04:35 AM
I don't find mousehover event under button. But when I copy and paste the code I don't get any error and mousehover event doesn't fire. I am using a student version of Visual Studio. Will there be any limitations because of that. Please let me know.

Thank you so much for the help. I appreciate it.There are no differences that way I think. But you need to add this delegates to the controls so they are used, otherwise they never would be called

using an delegate always needs two actions: a) creating the delegate
b) connectiong it to the event where it should be fired
a) is already done
b) is to be done in the property window - event section
Doing that writes code to the formDesign.cs See attached picture

bharusri
March 23rd, 2010, 03:30 PM
I know about adding a delegate. But the problem is I can see all the events under button. I am referring to the same image that you posted. I cannot see MouseHover, MouseLeave and few more events. I can paste a screenshot of it later this evening since I do not have my laptop right now.

Thank you

Arjay
March 23rd, 2010, 04:11 PM
I know about adding a delegate. But the problem is I can see all the events under button. I am referring to the same image that you posted. I cannot see MouseHover, MouseLeave and few more events. I can paste a screenshot of it later this evening since I do not have my laptop right now.

Thank youWhat version of Visual Studio are you using?

Here's what it looks like on VS 2008.

bharusri
March 24th, 2010, 12:21 AM
I am using VS2008. Sorry I forgot to mention that I am developing an application for Smart phone. In VS2008 for a windows form I could find all the events but for smart phone interface I do not find all those events. Please find attached the screenshot.

Arjay
March 24th, 2010, 12:23 AM
I am using VS2008. Sorry I forgot to mention that I am developing an application for Smart phone.Looks like they aren't available for the smart phone.

HanneSThEGreaT
March 24th, 2010, 02:07 AM
bharusri, please have a look here for future posts :

http://www.codeguru.com/forum/showthread.php?t=401115

bharusri
March 26th, 2010, 07:59 PM
Sorry for not being clear. I am using .NET 3.5 and Visual Studio 2008. I am developing an application for a smart phone.

Thank you