Files
docs-desktop/dotnet-desktop-guide/net/winforms/input-keyboard/how-to-handle-forms.md
T
Andy De GeorgeandGenevieve Warren 184e6c9a0c Initial publish of WinForms for .NET 5. (#96)
* Migrate inprogress winforms contnet from docs

* Fix preview note

* Fix vb code

* Minor fixes to keyboard articles

* Minor adjustment to overview

* Test redirects for 4.0 -> 5.0

* adjust links

* Add mouse input section winforms (#81)

* Update projects to .NET 5

* Update keyboard desc

* Finish mouse events

* Add remaining mouse articles;code

* finish mouse input

* minor fixes

* Remove branch restriction (#82)

* Update build-validation.yml (#84)

* Update build-validation.yml (#85)

* Fix vb proj

* Add WinForms tutorial (#91)

* redirect between overview

* New create an app tutorial

* Fix markdown

* Fix preserve view setting

* Add forms articles (#93)

* Add forms articles

* Fix warnings

* Winforms publish (#95)

* Prep TOC for publish

* Updated date

* Automatic how-to topic type

* Update desc/headers

* Fix links

* Fix build errors

* Add preview note

* Update toc landing page

* Convert old style project files

* update download links

* Apply suggestions from code review

Co-authored-by: Genevieve Warren <[email protected]>

* Adjust number key

* Update dotnet-desktop-guide/net/winforms/overview/index.md

* Try toc position task via bookmark

* Improve images

* Remove sentence

* File redirects

Co-authored-by: Genevieve Warren <[email protected]>
2020-10-28 10:44:16 -07:00

1.7 KiB

title, description, ms.date, dev_langs, helpviewer_keywords
title description ms.date dev_langs helpviewer_keywords
Handle keyboard input at the Form level Learn how to handle keyboard input for your Windows Forms at the form level, before messages reach a control. 10/26/2020
csharp
vb
keyboard input [Windows Forms], at form level
Windows Forms, handling keyboard input
keyboards [Windows Forms], form-level input

How to handle keyboard input messages in the form (Windows Forms .NET)

Windows Forms provides the ability to handle keyboard messages at the form level, before the messages reach a control. This article shows how to accomplish this task.

[!INCLUDE desktop guide under construction]

Handle a keyboard message

Handle the xref:System.Windows.Forms.Control.KeyPress or xref:System.Windows.Forms.Control.KeyDown event of the active form and set the xref:System.Windows.Forms.Form.KeyPreview%2A property of the form to true. This property causes the keyboard to be received by the form before they reach any controls on the form. The following code example handles the xref:System.Windows.Forms.Control.KeyPress event by detecting all of the number keys and consuming 1, 4, and 7.

:::code language="csharp" source="snippets/how-to-handle-forms/csharp/Form1.cs" id="HandleKey"::: :::code language="vb" source="snippets/how-to-handle-forms/vb/Form1.vb" id="HandleKey":::

See also