Control.OnLeave メソッドとは? わかりやすく解説

Control.OnLeave メソッド

Leave イベント発生させます

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

Protected Overridable Sub
 OnLeave ( _
    e As EventArgs _
)
Dim e As EventArgs

Me.OnLeave(e)
protected virtual void OnLeave (
    EventArgs e
)
protected:
virtual void OnLeave (
    EventArgs^ e
)
protected void OnLeave (
    EventArgs e
)
protected function OnLeave (
    e : EventArgs
)

パラメータ

e

イベント データ格納している EventArgs。

解説解説
使用例使用例

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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からControl.OnLeave メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からControl.OnLeave メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からControl.OnLeave メソッド を検索

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

辞書ショートカット

すべての辞書の索引

「Control.OnLeave メソッド」の関連用語

Control.OnLeave メソッドのお隣キーワード
検索ランキング

   

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



Control.OnLeave メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS