CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2011
    Posts
    1

    Unhappy BackColor unchanged with Mouse Hover

    Hi,
    I wanna know how to keep the BackColor value of a button controller unchanged even moving mouse pointer over the button (MouseHover event). I've searched for a solution over many forums but most of them said set the values as follows.

    void Button1MouseEnter(object sender, EventArgs e)
    {
    button1.UseVisualStyleBackColor = false;
    button1.BackColor = Color.Lavender;
    }

    void Button1MouseLeave(object sender, EventArgs e)
    {
    button1.UseVisualStyleBackColor = true;
    button1.BackColor = Color.Lavender;
    }

    But this doesn't work . Can anyone please help me?

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

    Re: BackColor unchanged with Mouse Hover

    What is the reasoning behind this? Buttons in Windows work in a certain way across most applications, and consistency is a good thing in a UI. You can always just draw the button yourself, but I question the logic behind doing this at all.

  3. #3
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    Re: BackColor unchanged with Mouse Hover

    I echo what BigEd said, but you can do this this way I think (i.e. I didn't actually check):

    Code:
    Color normalColor;
    //Call when the form is initializing
    void init()
    {
        normalColor = button1.BackColor;
    }
    
    void Button1MouseEnter(object sender, EventArgs e)
    {
        button1.BackColor = Color.Lavender;
    }
    
    void Button1MouseLeave(object sender, EventArgs e)
    {
        button1.BackColor = normalColor;
    }
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  4. #4
    Join Date
    Jul 2007
    Location
    Illinois
    Posts
    517

    Re: BackColor unchanged with Mouse Hover

    Try changing the buttons FlatStyle property to Flat and then adjusting the child properties of the FlatAppearance property for the button. If visual styles for the button are enabled, you aren't left with very many options.
    Last edited by RaleTheBlade; February 18th, 2011 at 01:30 PM.
    R.I.P. 3.5" Floppy Drives
    "I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured