Edit

Share via


Form.Shown Event

Definition

Occurs whenever the form is first displayed.

public:
 event EventHandler ^ Shown;
public event EventHandler Shown;
public event EventHandler? Shown;
member this.Shown : EventHandler 
Public Custom Event Shown As EventHandler 

Event Type

Examples

The following example demonstrates the use of this member. In the example, an event handler reports on the occurrence of the Shown event. This report helps you to learn when the event occurs and can assist you in debugging. To report on multiple events or on events that occur frequently, consider replacing MessageBox.Show with Console.WriteLine or appending the message to a multiline TextBox.

To run the example code, paste it into a project that contains an instance of type Form named Form1. Then ensure that the event handler is associated with the Shown event.

private void Form1_Shown(Object sender, EventArgs e) {

   MessageBox.Show("You are in the Form.Shown event.");
}
Private Sub Form1_Shown(sender as Object, e as EventArgs) _ 
     Handles Form1.Shown

   MessageBox.Show("You are in the Form.Shown event.")

End Sub

Remarks

The Shown event is only raised the first time a form is displayed; subsequently minimizing, maximizing, restoring, hiding, showing, or invalidating and repainting will not raise this event. For more information about the order of events of a form, see Order of Events in Windows Forms.

For more information about handling events, see Handling and Raising Events.

Applies to

See also