KeyGesture Constructors
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the KeyGesture class.
KeyGesture(Key) |
Initializes a new instance of the KeyGesture class with the specified Key. |
KeyGesture(Key, ModifierKeys) |
Initializes a new instance of the KeyGesture class with the specified Key and ModifierKeys. |
KeyGesture(Key, ModifierKeys, String) |
Initializes a new instance of the KeyGesture class with the specified Key, ModifierKeys, and display string. |
Initializes a new instance of the KeyGesture class with the specified Key.
public:
KeyGesture(System::Windows::Input::Key key);
public KeyGesture (System.Windows.Input.Key key);
new System.Windows.Input.KeyGesture : System.Windows.Input.Key -> System.Windows.Input.KeyGesture
Public Sub New (key As Key)
Parameters
- key
- Key
The key associated with this gesture.
Exceptions
key
is not a valid Key.
key
is not a valid KeyGesture.
Examples
The following example shows how to use this constructor to create a KeyGesture and associate it with a KeyBinding. The KeyBinding is then added to the InputBindingCollection of a Window.
KeyGesture OpenCmdKeyGesture = new KeyGesture(Key.F12);
KeyBinding OpenKeyBinding = new KeyBinding(
ApplicationCommands.Open,
OpenCmdKeyGesture);
this.InputBindings.Add(OpenKeyBinding);
Dim OpenCmdKeyGesture As New KeyGesture(Key.F12)
Dim OpenKeyBinding As New KeyBinding(ApplicationCommands.Open, OpenCmdKeyGesture)
Me.InputBindings.Add(OpenKeyBinding)
Remarks
In most cases, a KeyGesture must be associated with one or more ModifierKeys. The exceptions to this rule are the function keys and the numeric keypad keys, which can be a valid KeyGesture by themselves.
See also
Applies to
.NET Framework 4.8.1 and other versions
Product | Versions |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
Initializes a new instance of the KeyGesture class with the specified Key and ModifierKeys.
public:
KeyGesture(System::Windows::Input::Key key, System::Windows::Input::ModifierKeys modifiers);
public KeyGesture (System.Windows.Input.Key key, System.Windows.Input.ModifierKeys modifiers);
new System.Windows.Input.KeyGesture : System.Windows.Input.Key * System.Windows.Input.ModifierKeys -> System.Windows.Input.KeyGesture
Public Sub New (key As Key, modifiers As ModifierKeys)
Parameters
- key
- Key
The key associated with the gesture.
- modifiers
- ModifierKeys
The modifier keys associated with the gesture.
Exceptions
key
and modifiers
do not form a valid KeyGesture.
Examples
The following example shows how to use this constructor to create a KeyGesture and associate it with a KeyBinding. The KeyBinding is then added to the InputBindingCollection of a Window.
KeyGesture CloseCmdKeyGesture = new KeyGesture(
Key.L, ModifierKeys.Alt);
KeyBinding CloseKeyBinding = new KeyBinding(
ApplicationCommands.Close, CloseCmdKeyGesture);
this.InputBindings.Add(CloseKeyBinding);
Dim CloseCmdKeyGesture As New KeyGesture(Key.L, ModifierKeys.Alt)
Dim CloseKeyBinding As New KeyBinding(ApplicationCommands.Close, CloseCmdKeyGesture)
Me.InputBindings.Add(CloseKeyBinding)
Remarks
In most cases, a KeyGesture must be associated with one or more ModifierKeys. The exceptions to this rule are the function keys and the numeric keypad keys, which can be a valid KeyGesture by themselves.
See also
Applies to
.NET Framework 4.8.1 and other versions
Product | Versions |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
Initializes a new instance of the KeyGesture class with the specified Key, ModifierKeys, and display string.
public:
KeyGesture(System::Windows::Input::Key key, System::Windows::Input::ModifierKeys modifiers, System::String ^ displayString);
public KeyGesture (System.Windows.Input.Key key, System.Windows.Input.ModifierKeys modifiers, string displayString);
new System.Windows.Input.KeyGesture : System.Windows.Input.Key * System.Windows.Input.ModifierKeys * string -> System.Windows.Input.KeyGesture
Public Sub New (key As Key, modifiers As ModifierKeys, displayString As String)
Parameters
- key
- Key
The key associated with the gesture.
- modifiers
- ModifierKeys
The modifier keys associated with the gesture.
- displayString
- String
A string representation of the KeyGesture.
Exceptions
displayString
is null
.
key
and modifiers
do not form a valid KeyGesture.
Remarks
The DisplayString property is set to the displayString
parameter.
See also
Applies to
.NET Framework 4.8.1 and other versions
Product | Versions |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: