Why is MouseMove event firing when left mouse is clicked only for MouseDown event?

半腔热情 提交于 2019-11-28 10:40:04

问题


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.


回答1:


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:
  }
}


来源:https://stackoverflow.com/questions/8418738/why-is-mousemove-event-firing-when-left-mouse-is-clicked-only-for-mousedown-even

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!