Button.PerformClick (); not working in upload form

I call the click button in form_load as follows:

public void Form1_Load(object s, EventArgs e)
{
    button.PerformClick();
}

But when loading the buttons do not press, what am I doing wrong?

+4
source share
3 answers

This works for me:

public void Form1_Load(object s, EventArgs e){
  button.PerformClick();
}

It looks like you did not register Form1_Load as an event handler for the event of Loadyour form. Try the following:

public Form1(){
   InitializeComponent();
   Load += Form1_Load;//Register the event handler so that it will work for you.
}
+2
source

You can write whatever you want to do inside a click in another function, and call it from within the click handler or programmatically, like this -

public void Form1_Load(object s, EventArgs e)
    {
        //button.PerformClick();
        PerformClickAction();
    }

void button_click(object sender,EventArgs e) 
{
    PerformClickAction();
}

void PerformClickAction()
{
    // Write what you need to do on click
}
+6
source

, ,

public Form1()
{
        InitializeComponent();
        //Event fired
        this.Load += new System.EventHandler(this.button1_Click);

}

//Event Handler 
private void button1_Click(object sender, EventArgs e)
{
    //do something
}
0

All Articles