使用键盘钩子退出全屏

1、初始化

    //全屏窗体
    Form frmFullScreen;
    //键盘钩子
    private KeybordHook keybordHook;
    //实例化键盘钩子
    keybordHook = new KeybordHook();
    keybordHook.OnKeyDownEvent += keybordHook_OnKeyDownEvent;

2、按下事件

void keybordHook_OnKeyDownEvent(object sender, KeyEventArgs e)
    {
        switch (e.KeyCode)
        {
            case Keys.Escape:
               keybordHook.Start();
               frmFullScreen.Controls.Clear();
               Screen screen = Screen.FromControl(this);
               frmFullScreen.ShowIcon = false;
               frmFullScreen.Location = new Point(screen.Bounds.X, screen.Bounds.Y);
               frmFullScreen.WindowState = FormWindowState.Maximized;
              frmFullScreen.Show();
             case Keys.PageUp:
                //btnBack_Click(null, null);
                break;
               case Keys.PageDown:
                //btnNext_Click(null, null);
                break;
        }
    }

你可能感兴趣的:(小知识点)