How To Raise Click Event to Usercontrol Button in Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vajrala Narendra
    New Member
    • Jun 2007
    • 73

    How To Raise Click Event to Usercontrol Button in Form

    Hi Experts,
    am working with c#.net 3.5 windows application.

    in my project i have a usercontrol with only a single button.

    in my windows form based on some condition am displaying number of buttons here.
    for eample i want to display n number of buttons dynamically, here am displaying that usercontrol n times.

    but how can i raise clickevent to all those Usercontrol buttons in my windows form?


    Please share some code or ideas regarding this (Itz urgent)

    Thanks in Advance
    --Naren
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Of course its urgent.
    Start typing the following in Visual Studio.

    button bob = new button();
    bob.Click += new .....

    At this point VIsual Studio will fill in a new handler call for you, just follow the prompts to hit [TAB] to fill in the delegate and [TAB] again to have Visual Studio make a method for you.

    Comment

    • Vajrala Narendra
      New Member
      • Jun 2007
      • 73

      #3
      Thanks for replying
      but my requirement is not to create inside that form
      i want to create clickevent of a usercontrol inside windowsform.
      i may have more than one button, to all those buttons also i have to create events.

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Right...

        On your click event of the usercontrol make the new buttons. In my example I named them bob but you can call them whatever you like.
        Wen you make the new button, assign its click event to the handler of your choice.

        Comment

        • sammartin
          New Member
          • Mar 2009
          • 4

          #5
          How about Button.PerformC lick()

          Raises a click event on a button object

          HTH
          Sam

          Comment

          Working...