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.
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;
}
Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ? My latest articles : Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
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.
Last edited by bharusri; March 22nd, 2010 at 10:25 PM.
Re: How to change highlight color on button click in C#
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
Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ? My latest articles : Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
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.
Re: How to change highlight color on button click in C#
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.
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.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.