Soyez le premier à donner votre avis sur cette source.
Snippet vu 12 622 fois - Téléchargée 30 fois
using System; using System.ComponentModel; using System.Drawing; using System.Threading; using System.Windows.Forms; namespace WindowsApplication1 { public class Form1 : Form { private Icon ico1 = new Icon("ico1.ico"); private Icon ico2 = new Icon("ico2.ico"); public Form1() { InitializeComponent(); this.timer1.Interval = 1000; this.timer1.Start(); this.timer1.Tick += new EventHandler(timer1_Tick); } private void timer1_Tick(object sender, EventArgs e) { // Au tick du premier timer, on declenche un thread this.timer1.Stop(); Thread t = new Thread(new ThreadStart(ThreadMethod)); t.Start(); } private void ThreadMethod() { // Et dans ce thread, on declenche la méthode qui fera clignoter l'icone de la form // Via un appel synchrone à un délégué // Le null signifie que nous ne passons aucun parametre a la méthode (qui n'en attend pas) Invoke(new DoBlinkDelegate(DoBlink), null); } private System.Windows.Forms.Timer timerIcon = new System.Windows.Forms.Timer(); private delegate void DoBlinkDelegate(); private void DoBlink() { timerIcon.Interval = 1000; timerIcon.Tick+= new EventHandler(t_Tick); timerIcon.Start(); } private bool ico; void t_Tick(object sender, EventArgs e) { // Lors du tick du timer, on fait varier l'icone ico = !ico ? true : false; if (ico) this.notifyIcon1.Icon = ico1; else this.notifyIcon1.Icon = ico2; } private NotifyIcon notifyIcon1; private System.Windows.Forms.Timer timer1; private System.ComponentModel.IContainer components = null; private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); this.SuspendLayout(); // // notifyIcon1 // this.notifyIcon1.Text = "notifyIcon1"; this.notifyIcon1.Visible = true; // // Form1 // this.ClientSize = new System.Drawing.Size(292, 273); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } } }
17 août 2006 à 07:14
24 nov. 2005 à 17:28
using System.Timers;
Timer timerIcon = new Timer();
public Form1()
{
...
//indique que tous les événements du timer (qui s'exécutent sur un autre thread)
//seront déclenchés à travers Control.Invoke/BeginInvoke
timerIcon.SynchronizingObject = this;
timerIcon.Interval = 1000.0;
timerIcon.Elapsed += new ElapsedEventHandler( t_Tick );
}
private void ThreadMethod()
{
timerIcon.Start();
}
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.