Form.Activated Form.Activated Form.Activated Form.Activated Event

정의

폼이 코드에서 활성화되거나 사용자에 의해 활성화될 때 발생합니다.Occurs when the form is activated in code or by the user.

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

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 SetDesktopLocation, ClosedLoad, Activated, 및 Activate 멤버입니다.The following code example demonstrates how to use the SetDesktopLocation, Closed, Load, Activated, and Activate members. 예제를 실행 하려면 이라는 Form1 포함 된 폼에 다음 코드를 붙여 넣습니다를 Button 호출 Button1 두 개의 Label 컨트롤 이라는 Label1Label2합니다.To run the example, paste the following code in a form called Form1 containing a Button called Button1 and two Label controls called Label1 and Label2.

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

설명

참고

응용 프로그램은 활성 폼이 여러 개를 활성 폼이 입력된 포커스를 사용 하 여 폼입니다.When the application is active and has multiple forms, the active form is the form with the input focus. 보이지 않는 폼 활성 폼을 일 수 없습니다.A form that is not visible cannot be the active form. 표시 폼을 활성화 하는 가장 간단한 방법은 클릭는 적절 한 키보드 조합을 사용 하는 경우The simplest way to activate a visible form is to click it or use an appropriate keyboard combination.

호출 코드를 사용 하 여 런타임에 폼을 활성화 하는 Activate 메서드.To activate a form at run time using code, call the Activate method. 폼이 활성화 되지 않은 경우 폼의 데이터에 대 한 변경 내용에 따라 폼의 콘텐츠를 업데이트 하는 등의 작업에 대 한이 이벤트를 사용할 수 있습니다.You can use this event for tasks such as updating the contents of the form based on changes made to the form's data when the form was not activated.

이벤트 처리에 대한 자세한 내용은 이벤트 처리 및 발생 을 참조하십시오.For more information about handling events, see Handling and Raising Events.

적용 대상

추가 정보