Freigeben über


Control.KeyUp-Ereignis

Tritt ein, wenn eine Taste losgelassen wird, während das Steuerelement den Fokus hat.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Public Event KeyUp As KeyEventHandler
'Usage
Dim instance As Control
Dim handler As KeyEventHandler

AddHandler instance.KeyUp, handler
public event KeyEventHandler KeyUp
public:
event KeyEventHandler^ KeyUp {
    void add (KeyEventHandler^ value);
    void remove (KeyEventHandler^ value);
}
/** @event */
public void add_KeyUp (KeyEventHandler value)

/** @event */
public void remove_KeyUp (KeyEventHandler value)
JScript unterstützt die Verwendung von Ereignissen, aber nicht die Deklaration von neuen Ereignissen.

Hinweise

Tastaturereignisse treten in der folgenden Reihenfolge ein:

  1. KeyDown

  2. KeyPress

  3. KeyUp

Um Tastaturereignisse nur auf Formularebene zu behandeln und zu verhindern, dass andere Steuerelemente Tastaturereignisse empfangen, legen Sie die KeyPressEventArgs.Handled-Eigenschaft der KeyPress-Ereignisbehandlungsmethode des Formulars auf true fest. Bestimmte Tasten , z. B. die EINGABETASTE, TAB und ESC sowie die Pfeiltasten, werden von Steuerelementen automatisch behandelt. Damit diese Tasten das KeyUp-Ereignis auslösen, müssen Sie in jedem Steuerelement des Formulars die IsInputKey-Methode überschreiben. Der Code zum Überschreiben von IsInputKey muss bestimmen, ob eine der besonderen Tasten gedrückt wurde, und den Wert true zurückgeben.

Weitere Informationen zum Behandeln von Ereignissen finden Sie unter Behandeln von Ereignissen.

Beispiel

Im folgenden Codebeispiel wird das KeyUp-Ereignis mit der Help-Klasse verwendet, um dem Benutzer die Hilfe als Popup anzuzeigen.

' This example demonstrates how to use the KeyUp event with the Help class to display
' pop-up style help to the user of the application. When the user presses F1, the Help
' class displays a pop-up window, similar to a ToolTip, near the control. This example assumes
' that a TextBox control, named textBox1, has been added to the form and its KeyUp
' event has been contected to this event handler method.
Private Sub textBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles textBox1.KeyUp
    ' Determine whether the key entered is the F1 key. Display help if it is.
    If e.KeyCode = Keys.F1 Then
        ' Display a pop-up help topic to assist the user.
        Help.ShowPopup(textBox1, "Enter your first name", New Point(textBox1.Right, Me.textBox1.Bottom))
    End If
End Sub 'textBox1_KeyUp
// This example demonstrates how to use the KeyUp event with the Help class to display
// pop-up style help to the user of the application. When the user presses F1, the Help
// class displays a pop-up window, similar to a ToolTip, near the control. This example assumes
// that a TextBox control, named textBox1, has been added to the form and its KeyUp
// event has been contected to this event handler method.
private void textBox1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
    // Determine whether the key entered is the F1 key. Display help if it is.
    if(e.KeyCode == Keys.F1)
    {
        // Display a pop-up help topic to assist the user.
        Help.ShowPopup(textBox1, "Enter your first name", new Point(textBox1.Right, this.textBox1.Bottom));
    }
}
   // This example demonstrates how to use the KeyUp event with the Help class to display
   // pop-up style help to the user of the application. When the user presses F1, the Help
   // class displays a pop-up window, similar to a ToolTip, near the control. This example assumes
   // that a TextBox control, named textBox1, has been added to the form and its KeyUp
   // event has been connected to this event handler method.
private:
   void textBox1_KeyUp( Object^ /*sender*/, System::Windows::Forms::KeyEventArgs^ e )
   {
      
      // Determine whether the key entered is the F1 key. Display help if it is.
      if ( e->KeyCode == Keys::F1 )
      {
         
         // Display a pop-up help topic to assist the user.
         Help::ShowPopup( textBox1, "Enter your first name", Point(textBox1->Right,this->textBox1->Bottom) );
      }
   }
// This example demonstrates how to use the KeyUp event with the Help 
// class to display pop-up style help to the user of the application. 
// When the user presses F1, the Help class displays a pop-up window, 
// similar to a ToolTip, near the control. This example assumes that a 
// TextBox control, named textBox1, has been added to the form and its 
// KeyUp event has been contected to this event handler method.
private void textBox1_KeyUp(Object sender, 
    System.Windows.Forms.KeyEventArgs e)
{
    // Determine whether the key entered is the F1 key. 
    // Display help if it is.
    if (e.get_KeyCode().Equals(Keys.F1)) {
        // Display a pop-up help topic to assist the user.
        Help.ShowPopup(textBox1, "Enter your first name", 
            new Point(textBox1.get_Right(), this.textBox1.get_Bottom()));
    }
} //textBox1_KeyUp

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

Control-Klasse
Control-Member
System.Windows.Forms-Namespace
OnKeyUp
Control.KeyDown-Ereignis
Control.KeyPress-Ereignis