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. Passing mouse events over to the parent

Passing mouse events over to the parent

Scheduled Pinned Locked Moved C#
question
4 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.
  • D Offline
    D Offline
    Dy
    wrote on last edited by
    #1

    Hi there, I have a simple user control that I would like to handle mouse events for (such as mouse down etc.). My user control has a couple of Panel objects on it, and these are receiving the mouse events I am interested in. I would like the parent user control to handle the events instead of the panel objects (or anything I insert onto the parent). I understand that I can assign the panel (and any other child object's) mouse event handlers to be the event handler I wrote for the parent, and that works as desired, but I'm wondering if there is a better solution? So my question is: to have mouse events handled by a parent object, do I need to have each child object's event handler set to be the parent handler code, or is there a property I can set to automatically pass the event to the parent? Many thanks.

    - Dy

    L 1 Reply Last reply
    0
    • D Dy

      Hi there, I have a simple user control that I would like to handle mouse events for (such as mouse down etc.). My user control has a couple of Panel objects on it, and these are receiving the mouse events I am interested in. I would like the parent user control to handle the events instead of the panel objects (or anything I insert onto the parent). I understand that I can assign the panel (and any other child object's) mouse event handlers to be the event handler I wrote for the parent, and that works as desired, but I'm wondering if there is a better solution? So my question is: to have mouse events handled by a parent object, do I need to have each child object's event handler set to be the parent handler code, or is there a property I can set to automatically pass the event to the parent? Many thanks.

      - Dy

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, I would try setting Control.Enabled=false; for those Controls that should not react on keyboard and mouse. This would influence the rendering for some, not for Panel AFAIK. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      Voting for dummies? No thanks. X|


      D 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, I would try setting Control.Enabled=false; for those Controls that should not react on keyboard and mouse. This would influence the rendering for some, not for Panel AFAIK. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Voting for dummies? No thanks. X|


        D Offline
        D Offline
        Dy
        wrote on last edited by
        #3

        That technique works well, thank you Luc. As you said, it influences some controls paint jobs. Whilst that doesn't affect the control I'm working on at the moment, it probably will in the future, so I will continue to look for another means too.

        - Dy

        F 1 Reply Last reply
        0
        • D Dy

          That technique works well, thank you Luc. As you said, it influences some controls paint jobs. Whilst that doesn't affect the control I'm working on at the moment, it probably will in the future, so I will continue to look for another means too.

          - Dy

          F Offline
          F Offline
          Frank Horn
          wrote on last edited by
          #4

          I've had this problem too when the question came up whether a control could give users a possibility to drag child controls around. Either you don't use controls at all and do everything in the OnPaint method (which is pure hell), or you have to suscribe to the mouse events of all child controls. So far I haven't come up with anything better than a central ChildControl_MouseDown handler and a call in the constructor (after InitializeComponent) like foreach (control in this Controls) control.MouseDown+=ChildControl_MouseDown

          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