Changing Panel Opacity on MouseEnter

R

Ron

I have a simple form that contains a panel. I am overriding the base
OnMouseEnter/Leave events.

I want to fade the panel in when the user mouseovers the panel, and return
back to transparent when they mouse out.

This is my code thusfar, the MouseLeave doesnt appear to be working.

Thanks,
Ron

class TransparentPanel : Panel
{
public TransparentPanel()
{
}
protected enum ViewState
{
Visible, Hidden
}
protected int m_CurrentState = 0;

override protected CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x20;
return cp;
}
}

protected override void OnMouseEnter(EventArgs e)
{
Graphics g = this.CreateGraphics();
for (int i = 0; i <= 15; i++)
{
System.Threading.Thread.Sleep(10);
g.FillRectangle(new SolidBrush(Color.FromArgb(17,
SystemColors.Control)), this.ClientRectangle);
Application.DoEvents();
}
}

protected override void OnMouseLeave(EventArgs e)
{
Graphics g = this.CreateGraphics();
for (int i = 15; i >= 0; i--)
{
System.Threading.Thread.Sleep(10);
g.FillRectangle(new SolidBrush(Color.FromArgb(-17,
SystemColors.Control)), this.ClientRectangle);
Application.DoEvents();
}
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top