Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...