- 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);
-
- }
- }
- }
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);
}
}
}