1

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.

3
  • What do you mean the MouseMove event is not supposed to fire? Does your MouseDown event handler remove the MouseMove handler? Commented Dec 7, 2011 at 18:11
  • @rossisdead, well if all you are doing is clicking the left mousebutton and not moving the mouse pointer, then the only event that is expected to trigger or fire is MouseDown only not mousemove as well. Commented Dec 7, 2011 at 18:36
  • 1
    By design. MouseDown captures the mouse, MouseUp releases it. Windows wants to make sure that the window knows where the mouse is located after the capture ends so it generates an extra MouseMove message. This should never be a problem, can't see the rest of the code to tell why it could be. Commented Dec 7, 2011 at 19:17

1 Answer 1

7

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: } } 
Sign up to request clarification or add additional context in comments.

1 Comment

It happens because the mouse capture got released.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.