How to change highlight color on button click in C#
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
Re: How to change highlight color on button click in C#
Try this
Code:
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;
}
Re: How to change highlight color on button click in C#
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
Re: How to change highlight color on button click in C#
Quote:
Originally Posted by
bharusri
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
Yeah. Just wire up the same event handlers to each button.
Re: How to change highlight color on button click in C#
Or just make your own button class if this is going to be the theme of your app.
Re: How to change highlight color on button click in C#
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.
1 Attachment(s)
Re: How to change highlight color on button click in C#
Quote:
Originally Posted by
bharusri
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
Re: How to change highlight color on button click in C#
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
1 Attachment(s)
Re: How to change highlight color on button click in C#
Quote:
Originally Posted by
bharusri
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
What version of Visual Studio are you using?
Here's what it looks like on VS 2008.
1 Attachment(s)
Re: How to change highlight color on button click in C#
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.
Re: How to change highlight color on button click in C#
Quote:
Originally Posted by
bharusri
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.
Re: How to change highlight color on button click in C#
bharusri, please have a look here for future posts :
http://www.codeguru.com/forum/showthread.php?t=401115
Re: How to change highlight color on button click in C#
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
Re: How to change highlight color on button click in C#
Pls can u tell how to change the font of massage box..???