1. 程式人生 > >c# 窗體啟動後自動執行 Form_Load事件註冊及調用

c# 窗體啟動後自動執行 Form_Load事件註冊及調用

bject handle del 觸發 system event blog 聲明 文章

很多時候我們需要在程序一開始後立即觸發執行一些程序。這時候需要調用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
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!

c# 窗體啟動後自動執行 Form_Load事件註冊及調用