I have a panel control, that has a background picture on it. I want it to change opacity one I move mouse over it. How can I do that? I tried:
btnExit.BackColor = Color.FromArgb(20,63,63,63);
btnExit.BackColor = Color.FromArgb(20);
but nothing changes.. Any ideas why this is not working? this panel is sitting on another panel, which also has background picture. Thanks!
It can be done, as far as I know, with your method, but I guess that you have to refresh the control.
btnExit.Refresh();
EDIT:
First set your button FlatStyle to Flat .
this.btnExit.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
Then make two functions called btnExit_MouseHover and btnExit_MouseLeave:
void btnExit_MouseHover(object sender, EventArgs e)
{
btnExit.BackColor = Color.FromArgb(20, 63, 63, 63);
btnExit.Refresh();
}
void btnExit_MouseLeave(object sender, EventArgs e)
{
btnExit.BackColor = Color.FromArgb(100, 63, 63, 63);
btnExit.Refresh();
}
To activate these functions add two EventHandlers:
btnExit.MouseHover += new EventHandler(btnExit_MouseHover);
btnExit.MouseLeave += new EventHandler(btnExit_MouseLeave);
This will do the trick, now you only have to change the backcolor to the one you like ;).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.