How to call a button click action from a method?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fuzz13
    New Member
    • Jun 2010
    • 110

    #1

    How to call a button click action from a method?

    Within a method I want based on an if then statement to trigger a button click but I don't know how. Is there a way to call a button click event?
  • Fuzz13
    New Member
    • Jun 2010
    • 110

    #2
    Wow... should have used google:

    Code:
    button1.PerformClick();

    Comment

    • GaryTexmo
      Recognized Expert Top Contributor
      • Jul 2009
      • 1501

      #3
      Alternatively, you can just call the method tied to the click event.

      Code:
      Button myButton = new Button();
      myButton.Click += new EventHandler(ButtonClick);
      ...
      void ButtonClick(object sender, EventArgs e)
      {
        ...
      }
      ...
      ButtonClick(myButton, new EventArgs());

      Comment

      Working...