Control.Leave イベントとは? わかりやすく解説

Control.Leave イベント

入力フォーカスコントロール離れる発生します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

解説解説

キーボード (TabShift + Tab など) を使用するか、Select メソッドまたは SelectNextControl メソッド呼び出すか、ContainerControl.ActiveControl プロパティ現在のフォーム設定してフォーカス変更するとき、次の順序フォーカス イベント発生します

  1. Enter

  2. GotFocus

  3. Leave

  4. Validating

  5. Validated

  6. LostFocus

マウス使用するFocus メソッド呼び出してフォーカス変更するとき、フォーカス イベント次の順序発生します

  1. Enter

  2. GotFocus

  3. LostFocus

  4. Leave

  5. Validating

  6. Validated

CausesValidation プロパティfalse設定されている場合Validating イベントおよび Validated イベント発生しません。

メモメモ

Enter イベントおよび Leave イベントは、Form クラスによって中止されます。Form クラス等しイベントは、Activated イベントDeactivate イベントです。Enter イベントおよび Leave イベント階層構造になっており、適切なコントロール到達するまで、親チェイン次々移動します。たとえば、2 つの GroupBox コントロールを持つ Form があり、各 GroupBox コントロール1 つずつ TextBox コントロール持っているとしますカレット (^) が 1 つTextBox からもう 1 つテキスト ボックス移動すると、TextBox および GroupBox に対して Leave イベント発生し他方GroupBox および TextBox に対して Enter イベント発生します

イベント処理詳細については、「イベント利用」を参照してください

使用例使用例

Leave イベント使用してコントロール以前の状態にリセットするコード例次に示します

    Private Sub textBox1_Enter(sender As
 Object, e As System.EventArgs) Handles
 textBox1.Enter
        ' If the TextBox contains text, change its foreground and background
 colors.
        If textBox1.Text <> [String].Empty Then
            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)
        End If
    End Sub 'textBox1_Enter
   
   
    Private Sub textBox1_Leave(sender As
 Object, e As System.EventArgs) Handles
 textBox1.Leave
        ' Reset the colors and selection of the TextBox after focus
 is lost.
        textBox1.ForeColor = Color.Black
        textBox1.BackColor = Color.White
        textBox1.Select(0, 0)
    End Sub 'textBox1_Leave
End Class 'Form1 
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);
}
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);
      }
   }

   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);
   }
private void textBox1_Enter(Object sender,
 System.EventArgs e)
{
    // If the TextBox contains text, change its foreground and background
 
    // colors.
    if (!(textBox1.get_Text().Equals(""))) {
        textBox1.set_ForeColor(Color.get_Red());
        textBox1.set_BackColor(Color.get_Black());

        // Move the selection pointer to the end of the text of the
 
        // control.
        textBox1.Select(textBox1.get_Text().get_Length(), 0);
    }
} //textBox1_Enter

private void textBox1_Leave(Object sender,
 System.EventArgs e)
{
    // Reset the colors and selection of the TextBox after focus is
 lost.
    textBox1.set_ForeColor(Color.get_Black());
    textBox1.set_BackColor(Color.get_White());
    textBox1.Select(0, 0);
} //textBox1_Leave
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Control.Leave イベント」の関連用語

Control.Leave イベントのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Control.Leave イベントのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS