Reputation: 107
How to write just one code block for this two events ? I would like to execute same code when user minimize, resize or close form.
Upvotes: 0
Views: 81
Reputation: 26209
you can create a function for your common code and call it from whereever you want.
if you want to call it when the form is closed and resized write it as below:
private void Form1_Resize(object sender, EventArgs e)
{
myfunction();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
myfunction();
}
private void myfunction()
{
//function code here
}
Upvotes: 0
Reputation: 49013
this.Closing += (sender, e) => this.DoWork();
this.Resize += (sender, e) => this.DoWork();
private void DoWork()
{
// Your code here
}
Upvotes: 1
Reputation: 7676
Write a method for the functionality and call the method from the event handlers.
Upvotes: 2