C# 表单\关闭表单\调整事件处理程序的大小

C# 表单\关闭表单\调整事件处理程序的大小,c#,.net,C#,.net,如何只为这两个事件编写一个代码块? 我希望在用户最小化时执行相同的代码,调整或关闭窗体。为功能编写一个方法并从事件处理程序调用该方法。为功能编写一个方法并从事件处理程序调用该方法。为功能编写一个方法并从事件处理程序调用该方法。为功能编写一个方法并调用该方法从事件处理程序中。您可以为通用代码创建一个函数,并在任何需要的地方调用它 this.Closing += (sender, e) => this.DoWork(); this.Resize += (sender, e) => thi

如何只为这两个事件编写一个代码块?
我希望在用户最小化时执行相同的代码,调整或关闭窗体。

为功能编写一个方法并从事件处理程序调用该方法。

为功能编写一个方法并从事件处理程序调用该方法。

为功能编写一个方法并从事件处理程序调用该方法。

为功能编写一个方法并调用该方法从事件处理程序中。

您可以为通用代码创建一个函数,并在任何需要的地方调用它

this.Closing += (sender, e) => this.DoWork();
this.Resize += (sender, e) => this.DoWork();

private void DoWork()
{
    // Your code here
}
如果要在窗体关闭并调整大小时调用它,请按以下方式编写:

private void Form1_Resize(object sender, EventArgs e)
            {
                myfunction();
            }


            private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
                myfunction();
            }

      private void myfunction()
            {
                //function code here
            }

您可以为您的通用代码创建一个函数,并在任何需要的地方调用它

如果要在窗体关闭并调整大小时调用它,请按以下方式编写:

private void Form1_Resize(object sender, EventArgs e)
            {
                myfunction();
            }


            private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
                myfunction();
            }

      private void myfunction()
            {
                //function code here
            }

您可以为您的通用代码创建一个函数,并在任何需要的地方调用它

如果要在窗体关闭并调整大小时调用它,请按以下方式编写:

private void Form1_Resize(object sender, EventArgs e)
            {
                myfunction();
            }


            private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
                myfunction();
            }

      private void myfunction()
            {
                //function code here
            }

您可以为您的通用代码创建一个函数,并在任何需要的地方调用它

如果要在窗体关闭并调整大小时调用它,请按以下方式编写:

private void Form1_Resize(object sender, EventArgs e)
            {
                myfunction();
            }


            private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
                myfunction();
            }

      private void myfunction()
            {
                //function code here
            }