Results 1 to 5 of 5

Thread: Detecting when button is pressed in usercontrol

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2011
    Posts
    121

    Exclamation Detecting when button is pressed in usercontrol

    Hi!

    I have a form called Form1.

    I have two panels on that form.

    I load a usercontrol into one of those panels. That usercontrol contains a series of buttons. I want the form1 to detect when a button is pressed.

    Thanks.

  2. #2
    Fanatic Member x-ice's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    671

    Re: Detecting when button is pressed in usercontrol

    Quote Originally Posted by rqmok View Post
    Hi!

    I have a form called Form1.

    I have two panels on that form.

    I load a usercontrol into one of those panels. That usercontrol contains a series of buttons. I want the form1 to detect when a button is pressed.

    Thanks.
    You would need to add an event handler to each button that when fired will call a method on form1

    E.g. Button1.Click += new EventHandler(Form1_Button1_Click);

    Something like that. I hope this helps.

  3. #3
    Fanatic Member x-ice's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    671

    Re: Detecting when button is pressed in usercontrol

    If this isn't possible because of the fact that the buttons are in a user control you may need to use delegates.

    http://www.csharp-station.com/Tutorial/CSharp/lesson14
    http://www.dreamincode.net/forums/to...n-buttonclick/

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2011
    Posts
    121

    Re: Detecting when button is pressed in usercontrol

    Thanks x-ice. I will look into those links.

    Meanwhile, if anyone has any other way of doing this then please let me know.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2011
    Posts
    121

    Re: Detecting when button is pressed in usercontrol

    Thanks x-ice. I will look into those links.

    Meanwhile, if anyone has any other way of doing this then please let me know.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width