Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Not related to the core "Instance variable placement?" question</strong></p> <p>"A mouse move event in c# polls all the time. Sometimes I might want to only run the code inside it when the mouse position fully moves to another pixel."</p> <p>Huh?!...it doesn't fire for "partial pixels"...if these is such a thing. It fires when you have a new position based on whole pixels. It is possible to have the same position if you left the form and then re-entered at the same point, or maybe if focus switches and then returns and the cursor hasn't moved. There may be other conditions when it's possible...but have you actually tested to see how often the new position matches the previous position? I'm not sure what you're doing, but it doesn't happen very often on my system:</p> <pre><code>public partial class Form1 : Form { public Form1() { InitializeComponent(); this.MouseMove += new MouseEventHandler(example_MouseMove); listBox1.MouseMove += new MouseEventHandler(example_MouseMove); this.Shown += new EventHandler(Form1_Shown); } void Form1_Shown(object sender, EventArgs e) { _prevMousePosition = Cursor.Position; } private int counter = 0; private Point _prevMousePosition = new Point(0, 0); private void example_MouseMove(object sender, MouseEventArgs e) { if (_prevMousePosition == Cursor.Position) { counter++; listBox1.Items.Add(counter.ToString() + ": " + _prevMousePosition.ToString()); listBox1.SelectedIndex = listBox1.Items.Count - 1; } else { _prevMousePosition = Cursor.Position; this.Text = _prevMousePosition.ToString(); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload