2
votes

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!

1
If you are going to downrate provide a reason (comment)> I counter the cowardly downrate. - FrostyFire
what did I downrate? o_0 - Kristian
So, do you want the whole control to be semi-transparent? - John Koerner
@JohnKoerner that is correct. Or at least make it lighter/darker to fake it. Thanks - Kristian
Opacity is a tricky thing in winforms controls and doesn't work with overlapped controls. See this for more info - John Koerner

1 Answers

1
votes

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 ;).