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
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM