如何使用 C# 2015 中的表单设计器添加表单加载事件?(比如双击)? [英] How do I add a Form Load event using the form designer in C# 2015? (like double clicking)?
问题描述
我是 Visual Studio 2015 中的 C# 新手.我刚刚意识到通过双击项目添加事件处理程序的旧经典方法不再适用于表单(或窗口)等某些项目.
I am new to C# in Visual Studio 2015. I just realized that the old classical way of adding event handlers by double-clicking on the item no longer works for some items like the form (or the Window).
经过一些谷歌搜索后,我仍然无法找到使用设计器添加表单的 Load 事件的方法.
After some Google searches I still can't figure out a way to add the Load event of the form using the designer.
与 Visual Studio 2005 中的 Visual Basic 不同,我是否必须手动编写代码?
Do I have to manually write code for that unlike in Visual Basic in Visual Studio 2005?
推荐答案
您可以从控件的属性窗口设置加载事件 这里.您创建
You can set the Load event of a Control from its properties window here. You create the
private void Form1_Load(object sender, EventArgs e)
{
// my code
}
表单类中的事件,并在图片中箭头指向的位置填写其名称 (Form1_Load).
event in your form class, and fill in its name (Form1_Load) where the arrow points in the picture.
手动执行类似于:
Form1.Load += new System.EventHandler(this.Form1_Load);
考虑到您创建了 Form1_Load 事件.
considering that you created the Form1_Load event.
但最重要的是,双击应该工作.
But on top of all that, double clicking should work.
这篇关于如何使用 C# 2015 中的表单设计器添加表单加载事件?(比如双击)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!