Windows Phone Developers

Tuesday, January 22, 2008

VB.Net Control Events Life Cycle

Control Focus Events Cycle

When you change the focus by using the keyboard (TAB, SHIFT+TAB, and so on), by calling the Select or SelectNextControl methods, or by setting the 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

Private Sub DataGridView1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.Leave

MsgBox("leave")

End Sub

Private Sub DataGridView1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.LostFocus

MessageBox.Show("LostFocus")

End Sub

When you change the focus by using the mouse or by calling the Focus method, focus events occur in the following order:

1. Enter

2. GotFocus

3. LostFocus

4. Leave

5. Validating

6. Validated

If the CausesValidation property is set to false, the Validating and Validated events are suppressed.

NoteNote

The Enter and Leave events are suppressed by the Form class. The equivalent events in the Form class are the Activated and Deactivate events. The Enter and 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 Form with two GroupBox controls, and each GroupBox control has one TextBox control. When the caret is moved from one TextBox to the other, the Leave event is raised for the TextBox and GroupBox, and the Enter event is raised for the other GroupBox and TextBox.

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment