我是 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
FormandControlclasses 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.HandleCreatedControl.BindingContextChangedForm.LoadControl.VisibleChangedForm.ActivatedForm.ShownWhen an application closes, the shutdown events of the main form are raised in the following order:
Form.ClosingForm.FormClosingForm.ClosedForm.FormClosedForm.DeactivateThe
ApplicationExitevent of theApplicationclass is raised after the shutdown events of the main form.
方法命名 FormName_Event 也是设计使然的(至少在 IDE 中是这样)。您看到的是表单设计器生成的默认事件处理程序名称。如果您愿意,可以覆盖这些。
