【问题标题】:Button Image that has a glow effect具有发光效果的按钮图像
【发布时间】:2015-12-18 17:31:13
【问题描述】:

我正在使用 WinFroms。在我的应用程序中,我有一个我正在尝试操作的按钮。这个按钮有一个图像。在鼠标按下事件中,图像似乎被向下推,然后在鼠标向上事件中,图像似乎恢复到正常大小。

现在,当您将鼠标悬停在图像上时,我正在尝试创建一点发光效果。我怎样才能做到这一点?

按钮属性是:

扁平的外观

扁平风格 = 扁平

边框大小 = 0

鼠标向下返回颜色 = 透明

鼠标悬停颜色 = 透明

这是我的代码:

    Image Check = Resources.checkmark_icon;

    private void button1_MouseDown(object sender, MouseEventArgs e)
    {
        int Check_Width = Check.Width + ((Check.Width * -20) / 100);
        int Check_Height = Check.Height + ((Check.Height * -20) / 100);

        Bitmap Check_1 = new Bitmap(Check_Width, Check_Height);
        Graphics g = Graphics.FromImage(Check_1);
        g.DrawImage(Check, new Rectangle(Point.Empty, Check_1.Size));
        button1.Image = Check_1;
    }

    private void button1_MouseUp(object sender, MouseEventArgs e)
    {
        int Check_Width = Check.Width;
        int Check_Height = Check.Height;

        Bitmap Check_1 = new Bitmap(Check_Width, Check_Height);
        Graphics g = Graphics.FromImage(Check_1);
        g.DrawImage(Check, new Rectangle(Point.Empty, Check_1.Size));
        button1.Image = Check_1;
    }

    private void button1_MouseHover(object sender, EventArgs e)
    {

    }

【问题讨论】:

  • 这实际上非常简单,您需要创建没有GLOW1 图像和具有Glow 效果的2nd Image 还可以在以下How to create animated glow effect on Button Hover with C# 上进行谷歌搜索从字面上看,网上有Tons的例子,这是一个很好的例子*.com/questions/22138888/…
  • 感谢您的帮助。 @MethodMan

标签: c# .net image winforms button


【解决方案1】:

我使用 MethodMan 建议的 2 个图像在按钮中的图像上创建了发光效果。

第一张图片是发光复选标记。

第二张图片是一个不发光的复选标记。

    private void button1_MouseHover(object sender, EventArgs e)
    {
        button1.Image = Resources.glow_Check_mark_PNG;
    }

    private void button1_MouseLeave(object sender, EventArgs e)
    {
        button1.Image = Properties.Resources.checkmark_icon;
    }

【讨论】:

    最近更新 更多