Auf Englisch lesen

Teilen über


Form.Load Ereignis

Definition

Tritt ein, bevor ein Formular erstmals angezeigt wird.

C#
public event EventHandler Load;
C#
public event EventHandler? Load;

Ereignistyp

Beispiele

Im folgenden Beispiel wird veranschaulicht, wie die SetDesktopLocationMember , Load, Activatedund Activate verwendet werden. Fügen Sie zum Ausführen des Beispiels den folgenden Code in ein Formular namens Form1Button ein namens Button1 und zwei Label -Steuerelemente mit dem Namen Label1 und ein Label2.

C#
static int x = 200;
static int y = 200;

private void Button1_Click(System.Object sender, 
    System.EventArgs e)
{
    // Create a new Form1 and set its Visible property to true.
    Form1 form2 = new Form1();
    form2.Visible = true;

    // Set the new form's desktop location so it  
    // appears below and to the right of the current form.
    form2.SetDesktopLocation(x, y);
    x += 30;
    y += 30;

    // Keep the current form active by calling the Activate
    // method.
    this.Activate();
    this.Button1.Enabled = false;
}

// Updates the label text to reflect the current values of x 
// and y, which was were incremented in the Button1 control's 
// click event.
private void Form1_Activated(object sender, System.EventArgs e)
{
    Label1.Text = "x: "+x+" y: "+y;
    Label2.Text = "Number of forms currently open: "+count;
}

static int count = 0;

private void Form1_Closed(object sender, System.EventArgs e)
{
    count -= 1;
}

private void Form1_Load(object sender, System.EventArgs e)
{
    count += 1;
}

Hinweise

Sie können dieses Ereignis verwenden, um Aufgaben wie das Zuweisen von Ressourcen auszuführen, die vom Formular verwendet werden.

Weitere Informationen zur Behandlung von Ereignissen finden Sie unter behandeln und Auslösen von Ereignissen.

Gilt für:

Produkt Versionen
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Weitere Informationen