本文整理汇总了C#中System.Windows.Forms.KeyPressEventArgs类的典型用法代码示例。如果您正苦于以下问题:C# KeyPressEventArgs类的具体用法?C# KeyPressEventArgs怎么用?C# KeyPressEventArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyPressEventArgs类属于System.Windows.Forms命名空间,在下文中一共展示了KeyPressEventArgs类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TextBox
public class myKeyPressClass
{
static long keyPressCount = 0 ;
static long backspacePressed = 0;
static long returnPressed = 0 ;
static long escPressed = 0 ;
private TextBox textBox1 = new TextBox();
private void myKeyCounter(object sender, KeyPressEventArgs ex)
{
switch(ex.KeyChar)
{
// Counts the backspaces.
case '\b':
backspacePressed = backspacePressed + 1;
break ;
// Counts the ENTER keys.
case '\r':
returnPressed = returnPressed + 1 ;
break ;
// Counts the ESC keys.
case (char)27:
escPressed = escPressed + 1 ;
break ;
// Counts all other keys.
default:
keyPressCount = keyPressCount + 1 ;
break;
}
textBox1.Text =
backspacePressed + " backspaces pressed\r\n" +
escPressed + " escapes pressed\r\n" +
returnPressed + " returns pressed\r\n" +
keyPressCount + " other keys pressed\r\n" ;
ex.Handled = true ;
}
}
示例2: Form1
myKeyPressClass myKeyPressHandler = new myKeyPressClass();
public Form1()
{
InitializeComponent();
textBox1.KeyPress += new KeyPressEventHandler(myKeyPressHandler.myKeyCounter);
}