Control.OnEnter メソッド
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


イベントが発生すると、デリゲートを使用してイベント ハンドラが呼び出されます。詳細については、「イベントの発生」を参照してください。
OnEnter メソッドを使用すると、デリゲートを結び付けずに、派生クラスでイベントを処理することもできます。派生クラスでイベントを処理する場合は、この手法をお勧めします。
継承時の注意 派生クラスで OnEnter をオーバーライドする場合は、登録されているデリゲートがイベントを受け取ることができるように、基本クラスの OnEnter メソッドを呼び出してください。
Enter イベントを使用して、特定の条件で TextBox の前景色および背景色を変更するコード例を次に示します。
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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からControl.OnEnter メソッドを検索する場合は、下記のリンクをクリックしてください。

- Control.OnEnter メソッドのページへのリンク