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
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();
}
Is there a specific reason you need to actually click the button?
I would just move the code in the click event into a function, then call that function from both the load event and the click event. It will get around the need to call click()
For instance:
private void Form1_Shown(Object sender, EventArgs e)
{
DoFacebookLogin();
}
private void btnFacebookLogin_Click(Object sender, EventArgs e)
{
DoFacebookLogin();
}
private void DoFacebookLogin()
{
//Do Work here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With