📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SettingInterface
{
public partial class Form1 : Form
{
bool isClose = false;
public Form1()
{
InitializeComponent();
}
private Config ConInfo = new Config();
protected override void WndProc(ref Message m)
{
const int WM_HOTKEY = 0x0312;
//按快捷键
switch (m.Msg)
{
case WM_HOTKEY: MessageBox.Show("我有执行");
switch (m.WParam.ToInt32())
{
case 100: //按下的是Shift+S
//此处填写快捷键响应代码
isClose = true;
this.Close();
break;
case 101: //按下的是Ctrl+B
//此处填写快捷键响应代码
this.Close();
break;
case 102: //按下的是Alt+D
//此处填写快捷键响应代码
this.Show();
this.WindowState = FormWindowState.Normal;
break;
}
break;
}
base.WndProc(ref m);
}
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show(HotKey.RegisterHotKey(Handle, 100, HotKey.KeyModifiers.Shift, Keys.S).ToString());
//注册热键Ctrl+B,Id号为101。HotKey.KeyModifiers.Ctrl也可以直接使用数字2来表示。
HotKey.RegisterHotKey(Handle, 101, HotKey.KeyModifiers.Ctrl, Keys.B);
HotKey.RegisterHotKey(Handle, 102, HotKey.KeyModifiers.Alt, Keys.D);
}
private void btnHide_Click(object sender, EventArgs e)
{
this.Hide();
}
private void pbMain_MouseDown(object sender, MouseEventArgs e)
{
Form form1 = new frmSetting();
form1.ShowDialog();
MessageBox.Show(HotKey.RegisterHotKey(Handle, 100, HotKey.KeyModifiers.Shift, Keys.S).ToString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -