Question

Either I am not totally understanding how events work or Delphi Prism has gone mad!!!

I have a winform, mousedown event and mousemove event. Whenever I click the left mouse button only, MouseDown event fires as expected but ALSO MouseMove event fires right after when it is not suppose to.

Here is the piece of code from my winform designer where the methods are assigned to events.

  self.ClientSize := new System.Drawing.Size(751, 502);
  self.KeyPreview := true;
  self.Name := 'Maker';
  self.Text := 'Window Maker';
  self.Load += new System.EventHandler(@self.Maker_Load);
  self.FormClosing += new System.Windows.Forms.FormClosingEventHandler(@self.Maker_FormClosing);
  self.Shown += new System.EventHandler(@self.Maker_Shown);
  self.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(@self.Maker_MouseDoubleClick);
  self.MouseDown += new System.Windows.Forms.MouseEventHandler(@self.Maker_MouseDown);
  self.MouseMove += new System.Windows.Forms.MouseEventHandler(@self.Maker_MouseMove);
  self.MouseUp += new System.Windows.Forms.MouseEventHandler(@self.Maker_MouseUp);
  self.Paint += new System.Windows.Forms.PaintEventHandler(@self.Maker_Paint);
  self.ObjectPopup.ResumeLayout(false);
  self.ResumeLayout(false);

What am I doing wrong? Please, help I am getting frustrated over this, because I have mousemove events in other parts of my program. They work fine. I can't seem to figure out why this perticular mousemove event is acting up.

Was it helpful?

Solution

I forget the reason that happens.

But for a possible work around:

Point _LastPoint = Point.Empty;

private void Form1_MouseMove(object sender, MouseEventArgs e) {
  if (_LastPoint != e.Location) {
    _LastPoint = e.Location;
    // run MouseMove code:
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top