Dieser Artikel wurde maschinell übersetzt. Wenn Sie die englische Version des Artikels anzeigen möchten, aktivieren Sie das Kontrollkästchen Englisch. Sie können den englischen Text auch in einem Popupfenster anzeigen, indem Sie den Mauszeiger über den Text bewegen.
Übersetzung
Englisch

Control.Enter-Ereignis

 

Veröffentlicht: Oktober 2016

Wird beim Eintreten in den Bereich des Steuerelements ausgelöst.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public event EventHandler Enter

When you change the focus by using the keyboard (TAB, SHIFT+TAB, and so on), by calling the M:System.Windows.Forms.Control.Select or M:System.Windows.Forms.Control.SelectNextControl(System.Windows.Forms.Control,System.Boolean,System.Boolean,System.Boolean,System.Boolean) methods, or by setting the P:System.Windows.Forms.ContainerControl.ActiveControl property to the current form, focus events occur in the following order:

  1. Enter

  2. GotFocus

  3. Leave

  4. Validating

  5. Validated

  6. LostFocus

When you change the focus by using the mouse or by calling the M:System.Windows.Forms.Control.Focus method, focus events occur in the following order:

  1. Enter

  2. GotFocus

  3. LostFocus

  4. Leave

  5. Validating

  6. Validated

If the P:System.Windows.Forms.Control.CausesValidation property is set to false, the E:System.Windows.Forms.Control.Validating and E:System.Windows.Forms.Control.Validated events are suppressed.

System_CAPS_noteHinweis

The E:System.Windows.Forms.Control.Enter and E:System.Windows.Forms.Control.Leave events are suppressed by the T:System.Windows.Forms.Form class. The equivalent events in the T:System.Windows.Forms.Form class are the E:System.Windows.Forms.Form.Activated and E:System.Windows.Forms.Form.Deactivate events. The E:System.Windows.Forms.Control.Enter and E:System.Windows.Forms.Control.Leave events are hierarchical and will cascade up and down the parent chain until the appropriate control is reached. For example, assume you have a T:System.Windows.Forms.Form with two T:System.Windows.Forms.GroupBox controls, and each T:System.Windows.Forms.GroupBox control has one T:System.Windows.Forms.TextBox control. When the caret is moved from one T:System.Windows.Forms.TextBox to the other, the E:System.Windows.Forms.Control.Leave event is raised for the T:System.Windows.Forms.TextBox and T:System.Windows.Forms.GroupBox, and the E:System.Windows.Forms.Control.Enter event is raised for the other T:System.Windows.Forms.GroupBox and T:System.Windows.Forms.TextBox.

System_CAPS_cautionAchtung

Do not attempt to set focus from within the E:System.Windows.Forms.Control.Enter, E:System.Windows.Forms.Control.GotFocus, E:System.Windows.Forms.Control.Leave, E:System.Windows.Forms.Control.LostFocus, E:System.Windows.Forms.Control.Validating, or E:System.Windows.Forms.Control.Validated event handlers. Doing so can cause your application or the operating system to stop responding. For more information, see the WM_KILLFOCUS topic in the "Keyboard Input Reference" section and the "Message Deadlocks" section of theAbout Messages and Message Queueshttp://msdn.microsoft.com/library/windows/desktop/ms644927(v=vs.85).aspxtopic.

For more information about handling events, see Handling and Raising Events.

The following code example uses the E:System.Windows.Forms.Control.Enter event to change the foreground and background colors of a T:System.Windows.Forms.TextBox under particular conditions.

private void textBox1_Enter(object sender, System.EventArgs e)
{
    // If the TextBox contains text, change its foreground and background colors.
    if (textBox1.Text != String.Empty)
    {
        textBox1.ForeColor = Color.Red;
        textBox1.BackColor = Color.Black;
        // Move the selection pointer to the end of the text of the control.
        textBox1.Select(textBox1.Text.Length, 0);
    }
}

private void textBox1_Leave(object sender, System.EventArgs e)
{
    // Reset the colors and selection of the TextBox after focus is lost.
    textBox1.ForeColor = Color.Black;
    textBox1.BackColor = Color.White;
    textBox1.Select(0,0);
}

.NET Framework
Verfügbar seit 1.1
Zurück zum Anfang
Anzeigen: