KeyDown 事件即可判斷ixStart/iyStart,MouseMove 時比對是否位移if (ixStart == 0 && iyStart == 0) { ixStart = e.X; iyStart = e.Y; return; }
else if (e.X != ixStart || e.Y != iyStart)
{
Cursor.Show();
timerSaver.Enabled = false;
Application.Exit();
}
系統傳遞參數給螢幕保護程式:
/c:使用者按「設定」按鈕/a:使用者設定密碼本範例無選項,僅提示並結束:
if (args[0].Substring(0, 2).Equals("/c"))
{
MessageBox.Show("此螢幕保護無可設定選項!", "C# 螢幕保護",
MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
}
else if (args[0] == "/a")
{
MessageBox.Show("此螢幕保護無密碼設定選項!", "C# 螢幕保護",
MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
}
csc /t:winexe screen.cs
產生 Screen.exe → 改名 Screen.scr → 複製至 Windows\System32 目錄,完成安裝。