How to click a button on form load using C#

PriceCheaperton picture PriceCheaperton · Jan 11, 2014 · Viewed 18.7k times · Source

How do i click a button on foam load using C#? My button is called: btnFacebookLogin

I have tried this following:

private void Form1_Shown(Object sender, EventArgs e) 
{
   btnFacebookLogin.PerformClick(); 
}

I am using WinForms C# .NET 4

Answer

Justin Iurman picture Justin Iurman · Jan 11, 2014

Be sure to link your handler after InitializeComponent() and to Load event

public Form1()
{
   InitializeComponent();
   Load += Form1_Shown;
}

private void Form1_Shown(Object sender, EventArgs e) 
{
   btnFacebookLogin.PerformClick(); 
}