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 WindowsFormsApplication29 { public partial class Form1 : Form { Keys Old = Keys.None; public Form1() { InitializeComponent(); TextBox TB = new TextBox(); TB.Parent = this; TB.KeyDown += new KeyEventHandler(TB_KeyDown); TB.KeyUp += new KeyEventHandler(TB_KeyUp); } void TB_KeyUp(object sender, KeyEventArgs e) { Old = Keys.None; } void TB_KeyDown(object sender, KeyEventArgs e) { if (e.KeyData == Old) e.SuppressKeyPress = true; else Old = e.KeyData; } } }
这样的话,用户必须松开键才算完成一次按键操作。
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication29
{
public partial class Form1 : Form
{
Keys Old = Keys.None; public Form1()
{
InitializeComponent(); TextBox TB = new TextBox();
TB.Parent = this; TB.KeyDown += new KeyEventHandler(TB_KeyDown);
TB.KeyUp += new KeyEventHandler(TB_KeyUp);
} void TB_KeyUp(object sender, KeyEventArgs e)
{
Old = Keys.None;
} void TB_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Old)
e.SuppressKeyPress = true;
else
Old = e.KeyData;
}
}
}