How do I add a Form Load event using the form desi

2019-09-05 02:35发布

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).

After some Google searches I still can't figure out a way to add the Load event of the form using the designer.

Do I have to manually write code for that unlike in Visual Basic in Visual Studio 2005?

2条回答
乱世女痞
2楼-- · 2019-09-05 02:42

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
}

event in your form class, and fill in its name (Form1_Load) where the arrow points in the picture.

Doing it manually would be something like:

Form1.Load += new System.EventHandler(this.Form1_Load);

considering that you created the Form1_Load event.

But on top of all that, double clicking should work.

查看更多
Summer. ? 凉城
3楼-- · 2019-09-05 02:45

You may have an issue with your instillation. However, select the form and go to the actions window and select load. This should give the desired result

查看更多
登录 后发表回答