Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What event is raised when the mouse is moved while a button is pressed?

I need an event that doesn't exist in the .NET Framework's standard events. For example, mouse move while the left mouse button is down.

I also need to change some behaviors. For example, I have some buttons and I want to change the background image of each one that cursor is on while the left mouse button is down, but when I click on one button and hold down the left mouse button, when I move the mouse the other buttons will not raise any events.

What should I do? How can I create new events? How can I change behaviors?

Any help is appreciated.

like image 881
Soheil Avatar asked Dec 21 '22 18:12

Soheil


1 Answers

Your problem is that when the MouseDown event occurs on a button, that button 'captures' the mouse and doesn't release it until the button is released, which means that the MouseMove events are not received by the other buttons.

There's some code from here which may help:

 // Assuming all buttons subscribe to this event:
 private void buttons_MouseMove (object sender, MouseEventArgs e)
 {
   if (e.Button == System.Windows.Forms.MouseButtons.Left)
      {
       Control control = (Control) sender;
       if (control.Capture)
       {
          control.Capture = false;
       }
       if (control.ClientRectangle.Contains (e.Location)) 
       {
           Control.BackgroundImage = ...;
       }
    }
  }
like image 141
stuartd Avatar answered Dec 28 '22 06:12

stuartd