Tray Icon Animation
-
05-09-2019 - |
Frage
Ich weiß, wie ein Symbol im Windows-Infobereich zu platzieren (System Tray).
Was ist die beste Methode, ein Symbol animieren haben? Können Sie ein animiertes Gif verwenden, oder müssen Sie auf einen Timer setzen?
Ich bin mit C # und WPF, aber WinForms auch akzeptiert.
Lösung
z.
private void button1_Click(object sender, System.EventArgs e)
{
m_sysTray.StopAnimation();
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);
}
SetAnimationClip
verwendet den folgenden Code, um den Animationsrahmen zu erstellen
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());
}
}
den Rahmen StartAnimation
So animieren startet einen Timer und im Timer werden die Symbole geändert, um die gesamte Sequenz zu animieren.
public void StartAnimation(int interval, int loopCount)
{
if(m_animationIcons == null)
throw new ApplicationException("Animation clip not set with
SetAnimationClip");
m_loopCount = loopCount;
m_timer.Interval = interval;
m_timer.Start();
}
private void m_timer_Tick(object sender, EventArgs e)
{
if(m_currIndex < m_animationIcons.Length)
{
m_notifyIcon.Icon = m_animationIcons[m_currIndex];
m_currIndex++;
}
....
}
Mit SysTray
Erstellen und verdrahten Ihr Menü
ContextMenu m_menu = new ContextMenu();
m_menu.MenuItems.Add(0, new MenuItem("Show",new
System.EventHandler(Show_Click)));
Machen Sie sich ein Symbol, das Sie statisch in das Fach angezeigt werden sollen.
Erstellenein SysTray Objekt mit allen erforderlichen Informationen
m_sysTray = new SysTray("Right click for context menu",
new Icon(GetType(),"TrayIcon.ico"), m_menu);
Erstellen Bildstreifen mit dem Animations-Frames. Für 6 Rahmenleiste wird das Bild, das eine Breite von 6 * 16 und Höhe als 16 Pixel
Bitmap bmp = new Bitmap("tick.bmp");
// the color from the left bottom pixel will be made transparent
bmp.MakeTransparent();
m_sysTray.SetAnimationClip(bmp);
Starten Sie Animation anzeigt, wie oft Sie eine Schleife müssen die Animation und die Frame-Verzögerung
m_sysTray.StartAnimation(150, 5);
Animation Anruf beenden
m_sysTray.StopAnimation();
Andere Tipps
Ich denke, der beste Weg, dies zu tun ist, mehrere kleine Symbole, die Sie weiterhin die Systray-Objekt in das neue Bild von der Geschwindigkeit und der Grundlage der Zeit geändert werden.