c# 窗体启动后自动执行 Form_Load事件注册及调用

很多时候我们需要在程序一开始后立即触发执行一些程序。这时候需要调用Form_Load。 
首先编写事件程序块,编写完后即可再里面添加需要执行的代码。 
在结构体之后写就行。添加之前的代码如下: 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using GxIAPINET;

namespace watchGlass
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Load += new EventHandler(Form1_Load);
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void ButtonShutDown_Click(object sender, EventArgs e)
{
Process.Start("shutdown", "/s /t 0");
}

private void ButtonStart_Click(object sender, EventArgs e)
{

}
}
}
---------------------
作者:tomorrowNeverComes
来源:CSDN
原文:https://blog.csdn.net/dreamdonghui/article/details/78907085
版权声明:本文为博主原创文章,转载请附上博文链接!

原文地址:https://www.cnblogs.com/asdyzh/p/9846565.html