很多時候我們需要在程序一開始後立即觸發執行一些程序。這時候需要調用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)
{
}
}
}