Déclencher un click de souris automatique
lordjagg3d
-
chuka Messages postés 980 Statut Membre -
chuka Messages postés 980 Statut Membre -
Bonjour,
comment déclencher un click de souris automatique quel que soit l'emplacement de la souris?
Sur visual studio 2008 express.
comment déclencher un click de souris automatique quel que soit l'emplacement de la souris?
Sur visual studio 2008 express.
3 réponses
-
-
-
Tu peux t'inspirer de cela:
namespace WindowsFormsApplication1 { public delegate void SampleEventHandler(object sender, MouseEventArgs e); // Declare the event. public partial class Form1 : Form { public event SampleEventHandler SampleEvent; public Form1() { InitializeComponent(); this.SampleEvent+=new SampleEventHandler(Form1_SampleEvent); } private void Form1_SampleEvent(object sender, MouseEventArgs e) { //gestion de l'event déclenché... } private void Form1_MouseEnter(object sender, EventArgs e) { SampleEvent(this, new MouseEventArgs(MouseButtons.Right,1,MousePosition.X,MousePosition.Y,0)); } } }
un peu plus evolué....affiche la position de la souris...grace à un evenement MouseEventArgspublic delegate void SampleEventHandler(object sender, MouseEventArgs e); public delegate void AfficheDelegate(string m); // Declare the event. public partial class Form1 : Form { public event SampleEventHandler SampleEvent; Thread th; public Form1() { InitializeComponent(); this.SampleEvent+=new SampleEventHandler(Form1_SampleEvent); th = new Thread(Thread_PositionChanged); th.Start(); } private void affiche(string m) { if (InvokeRequired) Invoke(new AfficheDelegate(affiche), m); else textBox1.Text = m; } private void Form1_SampleEvent(object sender, MouseEventArgs e) { affiche(e.X + " " + e.Y); } private void Thread_PositionChanged() { while (true) { if ((MousePosition.X > this.Location.X && MousePosition.X < (this.Location.X + this.Width)) && (MousePosition.Y > this.Location.Y && MousePosition.Y < (this.Location.Y + this.Height))) { SampleEvent(this, new MouseEventArgs(MouseButtons.Right, 1, MousePosition.X, MousePosition.Y, 0)); } } } private void Form1_FormClosed(object sender, FormClosedEventArgs e) { th.Abort(); } }