Form.KeyPreview : Form « System.Windows.Forms « C# / C Sharp by API






Form.KeyPreview

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

namespace KeyPress
{
    /// <summary>
    /// Summary description for KeyPress.
    /// </summary>
    public class KeyPress : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public KeyPress()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
      this.button1 = new System.Windows.Forms.Button();
      this.button2 = new System.Windows.Forms.Button();
      this.SuspendLayout();
      // 
      // button1
      // 
      this.button1.Location = new System.Drawing.Point(184, 104);
      this.button1.Name = "button1";
      this.button1.Size = new System.Drawing.Size(80, 48);
      this.button1.TabIndex = 0;
      this.button1.Text = "button1";
      // 
      // button2
      // 
      this.button2.Location = new System.Drawing.Point(176, 192);
      this.button2.Name = "button2";
      this.button2.Size = new System.Drawing.Size(80, 32);
      this.button2.TabIndex = 1;
      this.button2.Text = "button2";
      // 
      // KeyPress
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(292, 273);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                  this.button2,
                                                                  this.button1});
      this.Name = "KeyPress";
      this.Text = "KeyPress";
      this.Load += new System.EventHandler(this.KeyPress_Load);
      this.ResumeLayout(false);

    }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new KeyPress());
        }

    private void KeyPress_Load(object sender, System.EventArgs e)
    {
      this.KeyPreview=true;
    }

    protected override void OnKeyPress(KeyPressEventArgs e)
    {
      MessageBox.Show("Key Pressed = " + e.KeyChar.ToString());
    }
    }
}

   
    
    
  








Related examples in the same category

1.new Form()
2.extends Form
3.Form.AcceptButton
4.Form.ActiveForm.Location
5.Form.Activated
6.Form.AddOwnedForm
7.Form.AutoScaleBaseSize
8.Form.AutoScroll
9.Form.AutoScrollMinSize
10.Form.BackColor
11.Form.CancelButton
12.Form.CenterToScreen()
13.Form.ClientRectangle
14.Form.ClientSize
15.Form.Closed
16.Form.Closing
17.Form.ContextMenu
18.Form.ControlBox
19.Form.Controls
20.Form.Cursor
21.Form.DesktopBounds
22.Form.DialogResult
23.Form.DisplayRectangle
24.Form.Dispose
25.Form.FormBorderStyle
26.Form.ForeColor
27.Form.GotFocus
28.Form.Height
29.Form.Hide()
30.Form.Invalidate
31.Form.IsMdiContainer
32.Form.KeyPress
33.Form.KeyUp
34.Form.Load
35.Form.Location
36.Form.MaximizeBox
37.Form.MaximumSize
38.Form.MdiParent
39.Form.MenuComplete
40.Form.Menu
41.Form.MinimizeBox
42.Form.MinimumSize
43.Form.MouseDown
44.Form.MouseLeave(All other events)
45.Form.MouseUp
46.Form.OnDragDrop
47.Form.OnDragOver
48.Form.OnInputLanguageChanged
49.Form.OnKeyDown
50.Form.OnKeyPress
51.Form.OnMouseEnter
52.Form.OnMouseHover
53.Form.OnMouseLeave
54.Form.OnMouseMove
55.Form.OnMouseWheel
56.Form.OnPaint(PaintEventArgs e)
57.Form.OnResize
58.Form.Opacity
59.Form.Paint
60.Form.Region
61.Form.Resize
62.Form.ResizeRedraw
63.Form.SetStyle
64.Form.ShowInTaskbar
65.Form.Size
66.Form.Show
67.Form.StartPosition
68.Form.SuspendLayout
69.Form.Text
70.Form.Top
71.Form.TransparencyKey
72.Form.Visible
73.Form.Width
74.Form.WindowState