|
public bool DllLoadResult = false;
private void Form1_Load(object sender, EventArgs e)
{//delphi一般在此初始化
try
{
DllLoadResult = InitializeWinIo();//加載WinIO
}
catch (System.Exception error)
{//WinIO加載失敗異常處理
MessageBox.Show(error.Message, "系統提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
if (!DllLoadResult)
{//加載WinIO失敗
Application.Exit();//退出系統,同Close()方法
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{//捕捉窗體Close事件,關閉窗口時提示
if (!DllLoadResult || MessageBox.Show("請您確認是否退出(Y/N)", "系統提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
if (DllLoadResult)
{
try
{
ShutdownWinIo();//卸載WinIO
}
catch (System.Exception error)
{//WinIO卸載失敗異常
MessageBox.Show(error.Message, "系統提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
e.Cancel = false;//允許退出系統
}
else
{
e.Cancel = true;//阻止退出系統
}
}
![]() |
|