Why am I not getting any MouseMove events when I click the mouse?

I have a MainPanel that contains myElement . When I click the mouse button on the panel and move it over myElement while still holding the button, myElement_MouseMove not called.

 private void myElement_MouseMove(object sender, MouseEventArgs e) { myElementStatus_lbl.Text = "I SEE YOU"; } 

This works when I do not hold the mouse button.

How to detect mouse movement at the click of a mouse button?

 this.MainPanel.Controls.Add(this.myElement); this.MainPanel.Location = new System.Drawing.Point(182, 84); this.MainPanel.Name = "MainPanel"; this.MainPanel.Size = new System.Drawing.Size(604, 309); this.MainPanel.TabIndex = 0; // // myElement // this.myElement.Location = new System.Drawing.Point(220, 67); this.myElement.Name = "myElement"; this.myElement.Size = new System.Drawing.Size(200, 100); this.myElement.TabIndex = 0; 
+4
source share
1 answer

I think this is due to the fact that drag events occur during mouse clicks. Therefore, when you hold down the mouse button and mouse, the drag enter element takes place.

You can detect mouse movements using one of the drag events. DragEnter , DragOver , DragLeave .

Edit: DoDragDrop disables MouseMove events

+5
source

Source: https://habr.com/ru/post/1482445/


All Articles