Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 托盘图标动画_C#_Wpf_System Tray_Notifyicon_Trayicon - Fatal编程技术网

C# 托盘图标动画

C# 托盘图标动画,c#,wpf,system-tray,notifyicon,trayicon,C#,Wpf,System Tray,Notifyicon,Trayicon,我知道如何在Windows通知区域(系统托盘)中放置图标 制作图标动画的最佳方法是什么?你可以使用动画gif,还是必须依赖计时器 我正在使用C#和WPF,但WinForms也被接受。我认为最好的方法是使用多个小图标,您可以根据速度和时间继续将systray对象更改为新图片。解释道 归结起来是: 制作一组图标,每个图标代表一个动画帧 在计时器事件上切换托盘中的图标 创建位图条。每帧为16x16像素 使用 e、 g SetAnimationClip使用以下代码创建动画帧 public void

我知道如何在Windows通知区域(系统托盘)中放置图标

制作图标动画的最佳方法是什么?你可以使用动画gif,还是必须依赖计时器


我正在使用C#和WPF,但WinForms也被接受。

我认为最好的方法是使用多个小图标,您可以根据速度和时间继续将systray对象更改为新图片。

解释道

归结起来是:

  • 制作一组图标,每个图标代表一个动画帧
  • 在计时器事件上切换托盘中的图标
  • 创建位图条。每帧为16x16像素
  • 使用
e、 g

SetAnimationClip
使用以下代码创建动画帧

public void SetAnimationClip (Bitmap bitmapStrip)
{
    m_animationIcons = new Icon[bitmapStrip.Width / 16];
    for (int i = 0; i < m_animationIcons.Length; i++)
    {
        Rectangle rect = new Rectangle(i*16, 0, 16, 16);
        Bitmap bmp = bitmapStrip.Clone(rect, bitmapStrip.PixelFormat);
        m_animationIcons[i] = Icon.FromHandle(bmp.GetHicon());
    }
}
使用SysTray

创建并连接菜单

ContextMenu m_menu = new ContextMenu();                                   
m_menu.MenuItems.Add(0, new MenuItem("Show",new
                     System.EventHandler(Show_Click)));
获取要在托盘中静态显示的图标

创建包含所有必需信息的SysTray对象

m_sysTray = new SysTray("Right click for context menu",
            new Icon(GetType(),"TrayIcon.ico"), m_menu);
使用动画帧创建图像条带。对于6帧带,图像的宽度为6*16,高度为16像素

Bitmap bmp = new Bitmap("tick.bmp");
// the color from the left bottom pixel will be made transparent
bmp.MakeTransparent();
m_sysTray.SetAnimationClip(bmp);
开始动画,指示需要循环动画和帧延迟的次数

m_sysTray.StartAnimation(150, 5);
停止动画调用

m_sysTray.StopAnimation();

一定要查看那篇文章的评论:“真丢脸:(代码中有很多漏洞。”()
m_sysTray.StartAnimation(150, 5);
m_sysTray.StopAnimation();