问题
I have a working form application that has a button on it. I have the source code too. So now I am trying to run the application from schedule tasks on windows and I would like to change the code the to the click button action when the application runs. The problem is the form should be loaded first and then the click action should be fired. Do I need a timer to this? if so could you please give me a help with this? So it takes about 3-4 seconds to load the form application. so it should fire the click action after 5 seconds
回答1:
The Form.Shown event will fire when the form is shown to the user for the first time, you can enter your event into this
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
this.BtnClick(null, null);
}
回答2:
You can call button click
event using Button.PerformClick on Form.Shown event to ensure form is loaded.
private void Form1_Shown(Object sender, EventArgs e)
{
Button1.PerformClick();
}
The Shown event is only raised the first time a form is displayed; subsequently minimizing, maximizing, restoring, hiding, showing, or invalidating and repainting will not raise this event, Reference
回答3:
buttonName.PerformClick();
Call the button using PerformClick method
回答4:
you call call button click like this
Button_Click(sender,e)
来源:https://stackoverflow.com/questions/17878730/how-to-automatically-click-a-button-on-a-form-application