Export (0) Print
Expand All
Expand Minimize

Control.ModifierKeys Property

Gets a value indicating which of the modifier keys (SHIFT, CTRL, and ALT) is in a pressed state.

[Visual Basic]
Public Shared ReadOnly Property ModifierKeys As Keys
[C#]
public static Keys ModifierKeys {get;}
[C++]
public: __property static Keys get_ModifierKeys();
[JScript]
public static function get ModifierKeys() : Keys;

Property Value

A bitwise combination of the Keys values. The default is None.

Example

[Visual Basic, C#, C++] The following example hides a button when the CTRL key is pressed while the button is clicked. This example assumes you have a Button named button1 on a Form.

[Visual Basic] 
Private Sub button1_Click(sender As Object, _
  e As EventArgs) Handles button1.Click
   ' If the CTRL key is pressed when the 
   ' control is clicked, hide the control. 
   If Control.ModifierKeys = Keys.Control Then
      CType(sender, Control).Hide()
   End If
End Sub

[C#] 
private void button1_Click(object sender, System.EventArgs e)
{
   /* If the CTRL key is pressed when the 
      * control is clicked, hide the control. */
   if(Control.ModifierKeys == Keys.Control)
   {
      ((Control)sender).Hide();
   }
}

[C++] 
private:
    void button1_Click(Object* sender, System::EventArgs* /*e*/) {
        /* If the CTRL key is pressed when the
         * control is clicked, hide the control. */
        if (Control::ModifierKeys == Keys::Control) {
            (dynamic_cast<Control*>(sender))->Hide();
        }
    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Control Class | Control Members | System.Windows.Forms Namespace | Keys

Show:
© 2014 Microsoft