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?
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.
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;
}
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.