Plateau animation Icône
-
05-09-2019 - |
Question
Je sais comment placer une icône dans la zone de notification Windows (barre d'état système).
Quelle est la meilleure méthode pour avoir un Animer icône? Pouvez-vous utiliser un GIF animé, ou avez-vous compter sur une minuterie?
J'utilise C # et WPF, mais WinForms accepté aussi.
La solution
par exemple.
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
utilise le code suivant pour créer l'image d'animation
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());
}
}
Pour animer le cadre StartAnimation
démarre une minuterie et la minuterie les icônes sont modifiées pour animer la séquence.
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++;
}
....
}
Utilisation SysTray
Créer et câbler votre menu
ContextMenu m_menu = new ContextMenu();
m_menu.MenuItems.Add(0, new MenuItem("Show",new
System.EventHandler(Show_Click)));
Obtenir une icône que vous souhaitez afficher statiquement dans le bac.
Créer un objet avec SysTray toutes les informations requises
m_sysTray = new SysTray("Right click for context menu",
new Icon(GetType(),"TrayIcon.ico"), m_menu);
Créer des bandes d'images avec les images d'animation. Pour 6 bande de trame de l'image aura une largeur de 6 * 16 et la hauteur de 16 pixels
Bitmap bmp = new Bitmap("tick.bmp");
// the color from the left bottom pixel will be made transparent
bmp.MakeTransparent();
m_sysTray.SetAnimationClip(bmp);
Lancer l'animation indiquant combien de fois vous avez besoin pour boucler l'animation et le retard de trame
m_sysTray.StartAnimation(150, 5);
Pour arrêter l'appel d'animation
m_sysTray.StopAnimation();
Autres conseils
Je pense que la meilleure façon de le faire est d'avoir plusieurs petites icônes que vous pouvez continuer à changer l'objet systray à la nouvelle image en fonction de la vitesse et le temps.