Alex Rivera | Logout

How can I detect a held down mouse button over a PictureBox?

Asked 2008-10-04T02:27:55.207
10

I need to fire an event when the mouse is above a PictureBox with the mouse button already clicked and held down.

Problems:

The MouseDown and MouseEnter event handlers do not work together very well.

For instance once a mouse button is clicked and held down, C# will fire the MouseDown event handler, but when the cursor moves over the PictureBox the MouseEnter event does not fire, until the mouse button is realeased.

Edit
Report

1 Answer

0

The best way to move a Form based on mouse position and control relative position is similar to what Ian Campbell posted.

    private void imgMoveWindow_MouseMove(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            Form1.ActiveForm.Left = Control.MousePosition.X - imgMoveWindow.Left - (imgMoveWindow.Size.Width/2);
            Form1.ActiveForm.Top = Control.MousePosition.Y - imgMoveWindow.Top - (imgMoveWindow.Size.Height/2); 
        }

    }

Where imgMoveWindow is a PictureBox Control.

Bruno Ratnieks

Sniffer Networks

answered 2011-05-19T15:05:05.920

Your Answer