c# - 部分打开c#窗体看不懂

标签 c#

我是 c# WinForms 的新手。我有 2 个问题。这段代码基本上告诉我们打开表单的部分。

第一个问题 form1_Activated 或 Form1_Show 或 button_Click 我的意思是所有这些都具有相同的形式“_”和方法名称的固定名称。它是否只是一种样式的语法。

我的第二个问题是程序如何知道应该先执行哪一个。我的意思是代码行是 activated-bindingContextChanged-Load... 但在输出中它是不同的。那是如何发生的,哪些代码使这成为可能

     private void Form1_Activated(object sender, EventArgs e)
     {
         Debug.Print("Activated");
     }
     private void Form1_BindingContextChanged(object sender, EventArgs e)
     {
         Debug.Print("BindingContextChanged");
     }
     private void Form1_Load(object sender, EventArgs e)
     {
         Debug.Print("Load Olayı");
     }
     private void Form1_Paint(object sender, PaintEventArgs e)
     {
         Debug.Print("Paint Olayı");
     }
     private void Form1_Shown(object sender, EventArgs e)
     {
         Debug.Print("Shown Olayı");
     }
     private void Form1_VisibleChanged(object sender, EventArgs e)
     {
         Debug.Print("VisibleChanged");
     }
     private void Form1_Validated(object sender, EventArgs e)
     {
         Debug.Print("Validated");
     }       
   } 
}

最佳答案

事件按照 Microsoft 设计的顺序发生:

通过https://msdn.microsoft.com/en-us/library/86faxx0d.aspx :

The Form and Control classes expose a set of events related to application startup and shutdown. When a Windows Forms application starts, the startup events of the main form are raised in the following order:

  • Control.HandleCreated
  • Control.BindingContextChanged
  • Form.Load
  • Control.VisibleChanged
  • Form.Activated
  • Form.Shown

When an application closes, the shutdown events of the main form are raised in the following order:

  • Form.Closing
  • Form.FormClosing
  • Form.Closed
  • Form.FormClosed
  • Form.Deactivate

The ApplicationExit event of the Application class is raised after the shutdown events of the main form.

方法命名 FormName_Event 也是设计使然的(至少在 IDE 中是这样)。您看到的是表单设计器生成的默认事件处理程序名称。如果您愿意,可以覆盖这些。

关于c# - 部分打开c#窗体看不懂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32102142/

相关文章:

c# - 按字段和值搜索过滤器

c# - 如何将 WriteLine 拆分为多行?

c# - 在 C# 中存储查询还是在 Postgres 中使用存储函数?

c# - 服务器上的 DateTime.Now 问题

c# - 如何在 Dynamics 365 SDK 中检索没有 Guid 的实体?

c# - 我应该在关闭后手动处理套接字吗?

c# - 继续过滤/查询分组依据到对象?

c# - 如何确保 winform 被垃圾收集?

c# - MS Access/accdb "Cannot open database"错误 (C#)

javascript - 如何调用c#编写的javascript函数,c#中按钮的onkeypress