Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Overriding OnMouseWheel

Overriding OnMouseWheel

Scheduled Pinned Locked Moved C#
question
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bekjong
    wrote on last edited by
    #1

    I've extended the PictureBox control to create my own user control. Now I want to capture the OnMouseWheel. I've done this many times, and it's usually enough to override like this

    protected override void OnMouseWheel(MouseEventArgs e)

    . Unfortunately the overidden method is never called when I turn my mousewheel. I've also tried tying the MouseWheel even to my own method. Weird enough, this isn't called either... Could this be related to the parent control the box is placed in? Any suggestions?

    Standards are great! Everybody should have one!

    T B 2 Replies Last reply
    0
    • B Bekjong

      I've extended the PictureBox control to create my own user control. Now I want to capture the OnMouseWheel. I've done this many times, and it's usually enough to override like this

      protected override void OnMouseWheel(MouseEventArgs e)

      . Unfortunately the overidden method is never called when I turn my mousewheel. I've also tried tying the MouseWheel even to my own method. Weird enough, this isn't called either... Could this be related to the parent control the box is placed in? Any suggestions?

      Standards are great! Everybody should have one!

      T Offline
      T Offline
      Thomas Stockwell
      wrote on last edited by
      #2

      You might try creating a user control that you know has the OnMouseWheel event enabled. Another option would be to inherit from the picturebox and override its WndProc with information related to the mouse wheel.

      Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my homepage Oracle Studios[^]

      B 1 Reply Last reply
      0
      • T Thomas Stockwell

        You might try creating a user control that you know has the OnMouseWheel event enabled. Another option would be to inherit from the picturebox and override its WndProc with information related to the mouse wheel.

        Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my homepage Oracle Studios[^]

        B Offline
        B Offline
        Bekjong
        wrote on last edited by
        #3

        The picture box should have this event enabled. I've tried the following and found it to be working: The form is placed within a SplitContainer control. Since I was guessing it might be the parent container that was the problem, I tried tying my method to SplitContainer.Panel1.MouseWheel event first. When this wasn't working, I tied it to SplitContainer.MouseWheel. This actually works. This seems very strange because I've always thought that events were passed from the toplevel container on to the back. The solution isn't very charming, since this means the control I made will have to be hooked differently to it's parent controls, depending on the type of parent it's placed In. Overriding its WndProc seems like a good idea, it's just that I have no idea of how to do this. If you can give me a pointer that would be very welcome, it's almost weekend for me and I don't feel like starting it with leaving an annoying problem like this unsolved ;)

        Standards are great! Everybody should have one!

        1 Reply Last reply
        0
        • B Bekjong

          I've extended the PictureBox control to create my own user control. Now I want to capture the OnMouseWheel. I've done this many times, and it's usually enough to override like this

          protected override void OnMouseWheel(MouseEventArgs e)

          . Unfortunately the overidden method is never called when I turn my mousewheel. I've also tried tying the MouseWheel even to my own method. Weird enough, this isn't called either... Could this be related to the parent control the box is placed in? Any suggestions?

          Standards are great! Everybody should have one!

          B Offline
          B Offline
          BoneSoft
          wrote on last edited by
          #4

          I know it's 4 years too late, but I ran across this post while looking for information on the Delta values in the MouseEventArgs passed to OnMouseWheel. The reason controls like PictureBox don't fire that event is because it doesn't have focus. An easy fix should be to override OnMouseEnter and calling the control's Focus() method. You may also need to call your control's SetStyle method and give it ControlStyles.Selectable in it's contructor. It's probably way too late, but I hope that helps anyway. :)

          "Political correctness is a doctrine, fostered by a delusional, illogical minority, and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end" - Unknown

          B 1 Reply Last reply
          0
          • B BoneSoft

            I know it's 4 years too late, but I ran across this post while looking for information on the Delta values in the MouseEventArgs passed to OnMouseWheel. The reason controls like PictureBox don't fire that event is because it doesn't have focus. An easy fix should be to override OnMouseEnter and calling the control's Focus() method. You may also need to call your control's SetStyle method and give it ControlStyles.Selectable in it's contructor. It's probably way too late, but I hope that helps anyway. :)

            "Political correctness is a doctrine, fostered by a delusional, illogical minority, and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end" - Unknown

            B Offline
            B Offline
            Bekjong
            wrote on last edited by
            #5

            Was surprised to see a reply to a 4 year old question that I didn't remember I asked in my inbox :). Thanks for the answer. Perhaps the problem has been haunting my subconsciousness for 4 years and is finally at peace ;). More likely I found a way around it back then though. Still; others may find your answer very useful, thanks again.

            Standards are great! Everybody should have one!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups