How to change highlight color on button click in C#
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: How to change highlight color on button click in C#

  1. #1
    Join Date
    Mar 2010
    Posts
    12

    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

  2. #2
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,537

    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

  3. #3
    Join Date
    Mar 2010
    Posts
    12

    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

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,413

    Re: How to change highlight color on button click in C#

    Quote Originally Posted by bharusri View Post
    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.

  5. #5
    Join Date
    Jun 2008
    Posts
    2,477

    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.

  6. #6
    Join Date
    Mar 2010
    Posts
    12

    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 11:25 PM.

  7. #7
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,537

    Re: How to change highlight color on button click in C#

    Quote Originally Posted by bharusri View Post
    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
    Attached Images Attached Images  
    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

  8. #8
    Join Date
    Mar 2010
    Posts
    12

    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

  9. #9
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,413

    Re: How to change highlight color on button click in C#

    Quote Originally Posted by bharusri View Post
    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.
    Attached Images Attached Images  

  10. #10
    Join Date
    Mar 2010
    Posts
    12

    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.
    Attached Images Attached Images  

  11. #11
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,413

    Re: How to change highlight color on button click in C#

    Quote Originally Posted by bharusri View Post
    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.

  12. #12
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,097

    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

  13. #13
    Join Date
    Mar 2010
    Posts
    12

    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

  14. #14
    Join Date
    Aug 2013
    Posts
    2

    Good work...

    This page help me so much


    thank you guys>....



    May god bless you

  15. #15
    Join Date
    Aug 2013
    Posts
    2

    Re: How to change highlight color on button click in C#

    Pls can u tell how to change the font of massage box..???

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center