Form.Closed 이벤트

정의

폼이 닫힐 때 발생합니다.

public:
 event EventHandler ^ Closed;
public event EventHandler Closed;
[System.ComponentModel.Browsable(false)]
public event EventHandler Closed;
[System.ComponentModel.Browsable(false)]
public event EventHandler? Closed;
member this.Closed : EventHandler 
[<System.ComponentModel.Browsable(false)>]
member this.Closed : EventHandler 
Public Custom Event Closed As EventHandler 

이벤트 유형

특성

예제

다음 예제에서는 , , , Load및 멤버를 SetDesktopLocation사용하는 방법을 보여 줍니다Activate. ActivatedClosed 예제를 실행하려면 라는 Button1 형식과 및 Label2라는 Form1 두 개의 Label 컨트롤을 Button 포함하는 다음 코드를 붙여넣습니다Label1.

static int x = 200;
static int y = 200;
void Button1_Click( System::Object^ sender, System::EventArgs^ e )
{
   
   // Create a new Form1 and set its Visible property to true.
   Form1^ form2 = gcnew 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.
void Form1_Activated( Object^ sender, System::EventArgs^ e )
{
   Label1->Text = String::Format( "x: {0} y: {1}", x, y );
   Label2->Text = String::Format( "Number of forms currently open: {0}", count );
}

static int count = 0;
void Form1_Closed( Object^ sender, System::EventArgs^ e )
{
   count -= 1;
}

void Form1_Load( Object^ sender, System::EventArgs^ e )
{
   count += 1;
}
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;
}
Shared x As Integer = 200
Shared y As Integer = 200

Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    ' Create a new Form1 and set its Visible property to true.
    Dim form2 As 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.
    Me.Activate()
    Me.Button1.Enabled = False
End Sub



' 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 Sub Form1_Activated(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles MyBase.Activated
    Label1.Text = "x: " & x & " y: " & y
    Label2.Text = "Number of forms currently open: " & count
End Sub

Shared count As Integer = 0

Private Sub Form1_Closed(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles MyBase.Closed
    count -= 1
End Sub

Private Sub Form1_Load(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
    count += 1
End Sub

설명

주의

이벤트는 Closed .NET Framework 버전 2.0에서 사용되지 않습니다. 대신 이벤트를 사용합니다FormClosed.

이 이벤트는 사용자가 양식을 닫은 후 또는 양식의 메서드에 Close 의해 발생합니다. 폼이 닫히지 않도록 하려면 이벤트를 처리 Closing 하고 이벤트 처리기에 전달된 의 CancelEventArgs 속성을 로 true설정합니다Cancel.

이 이벤트를 사용하여 양식에서 사용하는 리소스를 해제하는 등의 작업을 수행하고 양식에 입력된 정보를 저장하거나 부모 양식을 업데이트할 수 있습니다.

주의

Form.ClosedForm.Closing 이벤트는 발생 하는 경우를 Application.Exit 메서드를 호출 하 여 애플리케이션을 종료 합니다. 실행해야 하는 이러한 이벤트 중 하나에 유효성 검사 코드가 있는 경우 메서드를 호출하기 전에 열려 있는 각 양식에 대해 메서드를 Exit 개별적으로 호출 Form.Close 해야 합니다.

양식이 MDI 부모 양식인 경우 MDI 부모 폼 Closing 의 이벤트가 발생하기 전에 모든 MDI 자식 폼의 Closing 이벤트가 발생합니다. 또한 Closed MDI 부모 양식의 이벤트가 발생하기 전에 Closed 모든 MDI 자식 양식의 이벤트가 발생합니다.

이벤트 처리에 대한 자세한 내용은 이벤트 처리 및 발생 을 참조하십시오.

적용 대상

추가 정보