Displaying information about the key the user pressed : Key Event « Event « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Event » Key EventScreenshots 
Displaying information about the key the user pressed
Displaying information about the key the user pressed


   using System;
   using System.Drawing;
   using System.Collections;
   using System.ComponentModel;
   using System.Windows.Forms;
   using System.Data;

   public class KeyDemo : System.Windows.Forms.Form
   {
      private System.Windows.Forms.Label charLabel;
      private System.Windows.Forms.Label keyInfoLabel;
      public KeyDemo()
      {
         InitializeComponent();
      }

      private void InitializeComponent()
      {
         this.charLabel = new System.Windows.Forms.Label();
         this.keyInfoLabel = new System.Windows.Forms.Label();
         this.SuspendLayout();

         this.charLabel.Font = new System.Drawing.Font("Microsoft Sans Serif"12F);
         this.charLabel.Location = new System.Drawing.Point(88);
         this.charLabel.Name = "charLabel";
         this.charLabel.Size = new System.Drawing.Size(16832);
         this.charLabel.TabIndex = 0;

         this.keyInfoLabel.Font = new System.Drawing.Font("Microsoft Sans Serif"12F);
         this.keyInfoLabel.Location = new System.Drawing.Point(856);
         this.keyInfoLabel.Name = "keyInfoLabel";
         this.keyInfoLabel.Size = new System.Drawing.Size(168136);
         this.keyInfoLabel.TabIndex = 0;

         this.AutoScaleBaseSize = new System.Drawing.Size(1537);
         this.ClientSize = new System.Drawing.Size(184197);
         this.Controls.AddRange(new System.Windows.Forms.Control[] {this.keyInfoLabel,this.charLabel});
         this.Font = new System.Drawing.Font("Microsoft Sans Serif"24F);
         this.Name = "Key Demo";
         this.Text = "Key Demo";

         this.KeyDown +=new System.Windows.Forms.KeyEventHandler(this.KeyDemo_KeyDown );
         this.KeyPress +=new System.Windows.Forms.KeyPressEventHandler(this.KeyDemo_KeyPress );
         this.KeyUp +=new System.Windows.Forms.KeyEventHandler(this.KeyDemo_KeyUp );
         
         this.ResumeLayout(false);

      }
      [STAThread]
      static void Main() 
      {
         Application.Runnew KeyDemo() );
      }

      protected void KeyDemo_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e )
      {  
         charLabel.Text = "Key pressed: " + e.KeyChar;
      }

      private void KeyDemo_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e )
      {
         keyInfoLabel.Text = 
            "Alt: " (e.Alt ? "Yes" "No"'\n' +
            "Shift: " (e.Shift ? "Yes" "No" '\n' +
            "Ctrl: " (e.Control ? "Yes" "No" '\n' 
            "KeyCode: " + e.KeyCode + '\n' +
            "KeyData: " + e.KeyData + '\n' +
            "KeyValue: " + e.KeyValue;                               
      }
   
      private void KeyDemo_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e )
      {
        Console.WriteLine("Key up");
      }

   }

           
       
Related examples in the same category
1.Event system explained in detail
2.Close Form with Pressing X key
3.Check KeyCode from KeyEventArgs
4.Shift key pressedShift key pressed
5.Control Key pressedControl Key pressed
6.Alt key pressedAlt key pressed
7.Get Async Key StateGet Async Key State
8.Get Key action informationGet Key action information
9.Displays a key pressed by the userDisplays a key pressed by the user
10.Full screen and KeyEvent and MouseEvent
11.Key PressKey Press
12.Key Timer Key Timer
13.Keyboard SampleKeyboard Sample
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.