Control.Enter イベント
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

public: event EventHandler^ Enter { void add (EventHandler^ value); void remove (EventHandler^ value); }
/** @event */ public void add_Enter (EventHandler value) /** @event */ public void remove_Enter (EventHandler value)

キーボード (Tab、Shift + Tab など) を使用するか、Select メソッドまたは SelectNextControl メソッドを呼び出すか、ContainerControl.ActiveControl プロパティを現在のフォームに設定してフォーカスを変更するとき、次の順序でフォーカス イベントが発生します。
マウスを使用するか Focus メソッドを呼び出してフォーカスを変更するとき、フォーカス イベントは次の順序で発生します。
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 イベントが発生します。 |

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.Enter イベントを検索する場合は、下記のリンクをクリックしてください。

- Control.Enter イベントのページへのリンク