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. Hook Child events into Parent UserControl

Hook Child events into Parent UserControl

Scheduled Pinned Locked Moved C#
help
1 Posts 1 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.
  • M Offline
    M Offline
    mmuttmax
    wrote on last edited by
    #1

    Hi all, I was thinking there had to be an easier way to do this. I have a UserControl which contains a PictureBox and Label as children. I don't want to make the consumer have to hook the events or even expose the child controls. So how do you let the user add the event handler to the custom control and have it propagate down through to the children. I've done this which works but may give more explanation as to what I'm trying to do. Basically it's just assigning the event within the InitializeComponent(). private void SetPictureEventsToParent() { picture.MouseClick += new System.Windows.Forms.MouseEventHandler(picture_MouseClick); } void picture_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) { this.OnMouseClick(e); } private void SetLabelEventsToParent() { label.MouseClick += new System.Windows.Forms.MouseEventHandler(label_MouseClick); } void label_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) { this.OnMouseClick(e); } The problem is the Label and PictureBox cover the parent and so the parent never receives the event unless I do this. Thanx

    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