locked
Disable mouse wheel scroll on Panel RRS feed

  • Question

  • Hello,

    I have a PictureBox in a Panel, and I use the mouse wheel to zoom and rotate the PictureBox image. I want to disable the mouse wheel scroll on the panel and scroll it only by clicking the vertical and horisontal Scroll. Your help is valued.

    thanks in advance.

    - Visual Basic 2010 Express

    Thursday, March 28, 2013 10:07 AM

Answers

  • Hi simlai,

    You can override OnMouseWheel by create a custom Panel control.

    public class MyPanel : Panel
    {
        protected override void OnMouseWheel(MouseEventArgs e)
        {
    
            if (((Control.ModifierKeys & Keys.Alt) != Keys.Alt) && ((Control.ModifierKeys & Keys.Shift) != Keys.Shift))
            {
                ((HandledMouseEventArgs)e).Handled = true;
            }
            else
            {
                // do other staff
            }
        }
    }

    Best Regards,


    Bob Wu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Bob Wu-MT Friday, March 29, 2013 7:56 AM
    • Marked as answer by Simlali Friday, March 29, 2013 8:13 AM
    Friday, March 29, 2013 7:55 AM

All replies

  • you need to disable/bypass the mouse event

                if (e.Delta > 0) 
                {return;}


    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Thursday, March 28, 2013 11:05 AM
  • you need to disable/bypass the mouse event

    Thank you, but I am using the e.Delta to rotate and zoom the pictureBox image.

    when the user move the mouse over the I call the pictureBox.Select(), he can press the Shift key to zoom and the Alt key to rotate


    If altKeyPressed Then cardRotation += e.Delta / 260.0F
    If shiftKeyPressed Then cardZoom += e.Delta / 8000.0F
    PictureBox.Invalidate()
    
    what I need is to use the mouse wheel if the altKeyPressed = True  or shiftKeyPressed = True 

    Thursday, March 28, 2013 12:17 PM
  • Hi simlai,

    You can override OnMouseWheel by create a custom Panel control.

    public class MyPanel : Panel
    {
        protected override void OnMouseWheel(MouseEventArgs e)
        {
    
            if (((Control.ModifierKeys & Keys.Alt) != Keys.Alt) && ((Control.ModifierKeys & Keys.Shift) != Keys.Shift))
            {
                ((HandledMouseEventArgs)e).Handled = true;
            }
            else
            {
                // do other staff
            }
        }
    }

    Best Regards,


    Bob Wu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Bob Wu-MT Friday, March 29, 2013 7:56 AM
    • Marked as answer by Simlali Friday, March 29, 2013 8:13 AM
    Friday, March 29, 2013 7:55 AM