Reputation: 2364
I have a screenshot application where a user can pass command line arguments, and based on those arguments will determine the behaviour of the form.
I am trying to take a screenshot after the form has loaded, however I have the functionality to do this after InitializeComponent();
. Like so-
if (counts > 0)
{
generateScreenshotButton_Click(null, null);
button2_Click(null, null);
}
My problem being these functions are firing before the form has loaded. Therefore the screen shot is blank. How can I resolve this?
Upvotes: 1
Views: 326
Reputation: 113385
Add Load
event in your Form.cs
file.
There is a difference between InitializeComponent
and Form Load
. See What does InitializeComponent() do, and how does it work in WPF? It is for WPF but is same in Windows Forms.
Try this code:
public Form1()
{
InitializeComponent(); //this is the InitializeComponent method. this This method locates a URI to the XAML for the Window/UserControl that is loading, and passes it to the System.Windows.Application.LoadComponent() static method.
this.Load += new EventHandler(Form1_Load); //this create Load Form event
}
void Form1_Load(object sender, EventArgs e) //after your form is completely loaded, your program will run the code from here...
{
//your code goes here
}
Hope that I helped you.
Upvotes: 1