1.第一次窗體顯示前發生:spa
1 public FrmMain() 2 { 3 InitializeComponent(); 4 Load += FrmMain_Load; 5 }
2.主窗體Load事件code
1 private void FrmMain_Load(object sender, EventArgs e) 2 { 3 try 4 { 5 DateTime usetime = Convert.ToDateTime("xxxx/xx/xx 00:00:00"); 6 DateTime daytime = DateTime.Parse(System.DateTime.Now.ToLongDateString()); 7 TimeSpan ts = usetime - daytime; 8 int day = ts.Days; 9 if (day <= 0) 10 { 11 if (MessageBox.Show("軟件試用期已到,請註冊後再使用!", "提示", MessageBoxButtons.OK) == DialogResult.OK) 12 { 13 Application.Exit(); 14 } 15 } 16 else 17 { 18 //執行Load的代碼 19 } 20 } 21 catch { } 22 }