如何创建与C#的按钮哈弗动画光晕效果? [英] How to create animated glow effect on Button Hover with C#?

查看:259
本文介绍了如何创建与C#的按钮哈弗动画光晕效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个的CustomButton 我的应用程序的控制。现在,我想这样做,当鼠标上的按钮它应该显示光晕效果,当鼠标离开它应该回到正常的。但是,发光效果应该不会立即显示出来。它应与动画显示。就像在Chrome浏览器标签页即可。我曾尝试在按钮控制这个逻辑。

I am creating a CustomButton control for my application. Now, What I want to do that when the mouse goes on the button it should show glow effect and when mouse leave it should get back to normal. But the glow effect should not displayed immediately. It should display with animation. just like Chrome Browser Tab Page. I have tried this logic in the button control.

这是我的逻辑。但是,我认为这不是一个正确的方式。请建议适当的方式来获得光晕效果。

This is my logic. But, I think this is not a proper way. please suggest proper way to get glow effect.

private void ShowGlow()
{
    for (int i = 0; i<50; i+= 5)
    {
         Sleep(100);
         Graphics g = this.CreateGraphics();
         Color color = Color.FromArgb(i, 150,150,25);
         g.FillRectangle(new SolidBrush(color), this.ClientRectangle);
    }
}

其他详情
Visual Studio 2005中,Windows XP中,Windows窗体控件

Additional Details Visual Studio 2005, Windows XP, Windows Form Controls

推荐答案

我建议你一个简单的方法。
创建两个图像,具有发光效果和不带。
并使用此code。

I suggest you a simpler method. Create two images, with glow effect and without. And use this code.

在的MouseEnter:

private void MyButton_MouseEnter(object sender, EventArgs e)
{
    MyButton.BackgroundImage = Properties.Resources.WithGlow; 
}

在鼠标离开:

private void MyButton_MouseLeave(object sender, EventArgs e)
{
    MyButton.BackgroundImage = Properties.Resources.WithoutGlow; 
}

这是我平时在我的项目做的。

This is what I usually do in my projects.

这篇关于如何创建与C#的按钮哈弗动画光晕效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆