想给RichTextBox添加一个加快捷键试验了
private void RichTextBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
Interaction.MsgBox("2");
if (e.KeyCode == Keys.A) {
e.Handled = true;
e.SuppressKeyPress = false;
Interaction.MsgBox("OK e.KeyCode");
}
}
private void 测试_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
Interaction.MsgBox("OK测试_KeyDown");
e.SuppressKeyPress = true; Interaction.MsgBox("1");
}
private void Button2_Click(System.Object sender, System.EventArgs e)
{
this.IsInputKey(Keys.A);
// = True
this.KeyPreview = true;
}private void RichTextBox1_TextChanged(object sender, System.EventArgs e)
{
Interaction.MsgBox("3");
}
是可以触发事件但 RichTextBox1 内容发生了改变,而且RichTextBox1_TextChanged事件最早。
在不用隐藏菜单、HOOK的情况下如果实现快捷键。
private void RichTextBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
Interaction.MsgBox("2");
if (e.KeyCode == Keys.A) {
e.Handled = true;
e.SuppressKeyPress = false;
Interaction.MsgBox("OK e.KeyCode");
}
}
private void 测试_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
Interaction.MsgBox("OK测试_KeyDown");
e.SuppressKeyPress = true; Interaction.MsgBox("1");
}
private void Button2_Click(System.Object sender, System.EventArgs e)
{
this.IsInputKey(Keys.A);
// = True
this.KeyPreview = true;
}private void RichTextBox1_TextChanged(object sender, System.EventArgs e)
{
Interaction.MsgBox("3");
}
是可以触发事件但 RichTextBox1 内容发生了改变,而且RichTextBox1_TextChanged事件最早。
在不用隐藏菜单、HOOK的情况下如果实现快捷键。
解决方案 »
- C# 循环导入数据库 100条就报错
- 如何在.NetFramework 2.0环境下写一个自定义的箭头控件
- WinForm 多线程,高手请进!
- ASP.NET的WEB.CONFIG中allow标签的users和roles的区别
- 奇怪的事情 请大家看下
- 多线程问题
- 请大家帮个忙,急!!!
- C# http 下载异常
- 该用using System.IO还是用Import Namespace = "System.Io", 二者是一回事吗?谢谢
- 简单问题:为什么Console不能使用?(在线等待)
- DBdataadaper.update 删除时 不能并发执行的问题 求教各位高人
- 请教:webBrowser 能否捕获里网页中所操作的JS事件?
{
if (keyData == (Keys.Ctrl | Keys.I))
{
//你的事件
}
}
private void txtData_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.A)
MessageBox.Show("Ctrl+A");
if (e.Alt && e.KeyCode == Keys.A)
MessageBox.Show("Alt+A");
if (e.Shift && e.KeyCode == Keys.A)
MessageBox.Show("Shift+A");
}keydown里面抓KeyEventArgs就可以了
{
if (e.Control && e.KeyCode == Keys.C)
{
MessageBox.Show("copy?");
}
if (e.Control && e.KeyCode == Keys.V)
{
MessageBox.Show("paste?");
}
}
protected override void WndProc(ref System.Windows.Forms.Message m)
{
base.WndProc(ref m);
if(m.Msg == 0x0300 || m.Msg == 0x0301)
{
}
}