設定按下 F11 鍵切換表單全銀幕模式。
設定按下 Esc 鍵關閉表單。
Code Snippet:
//控制工作列隱藏或顯示。
private const int SW_HIDE = 0;
private const int SW_SHOW = 1;
[DllImport("user32.dll")]
private static extern int FindWindow(string className, string windowText);
[DllImport("user32.dll")]
private static extern int ShowWindow(int hwnd, int command);
private bool _bFullScreenMode = false;
private void Form1_Load(object sender, EventArgs e)
{
//設定表單上控制項的鍵盤事件是否和表單的鍵盤事件視同一起觸發。
this.KeyPreview = true;
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyData)
{
case Keys.Escape:
//顯示工作列。
ShowWindow(FindWindow("Shell_TrayWnd", ""), SW_SHOW);
this.Close();
break;
case Keys.F11:
_bFullScreenMode = !_bFullScreenMode;
if (_bFullScreenMode)
{
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
//隱藏工作列。
int hWnd = FindWindow("Shell_TrayWnd", "");
ShowWindow(hWnd, SW_HIDE);
}
else
{
this.FormBorderStyle = FormBorderStyle.Sizable;
this.WindowState = FormWindowState.Normal;
//顯示工作列。
int hWnd = FindWindow("Shell_TrayWnd", "");
ShowWindow(hWnd, SW_SHOW);
}
this.Select();
break;
default:
break;
}
}
沒有留言:
張貼留言