Provides data for the Control.KeyPress event.
http://msdn.microsoft.com/en-us/library/system.windows.forms.KeyPressEventArgs(v=vs.110).aspx
Inheritance: System.EventArgs
Beispiel #1
0
 void TextBox_KeyPress(object sender, KeyPressEventArgs e)
 {
     //if (this.ContainsFocus)
     if (Parent.Focused)
     {
         if (e.KeyChar < 32 || e.KeyChar >= 127)
         {
             if (e.KeyChar == (char)Keys.Back)
             {
                 if (Text.Length > 0)
                 {
                     Text = Text.Substring(0, Text.Length - 1);
                 }
                 else
                 {
                     Text = "";
                 }
             }
             else
             {
                 Text = Text;
             }
         }
         else
         {
             Text += e.KeyChar;
         }
     }
 }
 /// <summary>
 /// Raises the <see cref="KeyPress"/> event.
 /// </summary>
 /// <param name="e">A <see cref="KeyPressEventArgs"/> that contains the event data.</param>
 /// <remarks>
 /// http://msdn.microsoft.com/en-us/library/system.windows.forms.control.onkeypress(v=vs.110).aspx
 /// </remarks>
 protected virtual void OnKeyPress(KeyPressEventArgs e)
 {
     var handler = KeyPress;
     handler?.Invoke(this, e);
 }
Beispiel #3
0
 void KeyStateMan_KeyPress(object sender, KeyPressEventArgs e)
 {
     OnKeyPress(e);
 }