SSISO Community

갤러리정

PerformClick 메소드 : 다른컨트롤의 Click이벤트 실행 - CSharp

PerformClick 메소드

// 해당Control를 직접 Click하지 않고도 다른 Control의 Click 이벤트를 호출할수 있습니다.

// Button, MenuItem, RadioButton 컨트롤에서 사용가능하다..

 

//Button.PerformClick 메소드 사용 예제


Button button1 = new Button();
Button button2 = new Button();
RadioButton radioButton1 = new RadioButton();

 

this.button1.Name = "button1";
this.button1.Text = "버튼1";
this.button1.Click += new System.EventHandler(this.button1_Click);

 

this.button2.Name = "button2";
this.button2.Text = "버튼1/라디오버튼을 클릭합니다.";
this.button2.Click += new System.EventHandler(this.button2_Click);

 

this.radioButton1.Name = "radioButton1";
this.radioButton1.Text = "라디오버튼";
this.radioButton1.Click += new System.EventHandler(this.radioButton1_Click);

 

private void button1_Click(object sender, System.EventArgs e)
{
    MessageBox.Show("버튼1을 클릭하셨습니다.");
}

 

private void radioButton1_Click(object sender, System.EventArgs e)
{
   MessageBox.Show("라디오버튼을 클릭합니다.");
}

 

private void button2_Click(object sender, System.EventArgs e)
{
    //button2를 Click하면 button1과 라디어버튼의 Click이벤트를 실행합니다.
    this.button1.PerformClick();
    this.radioButton1.PerformClick();
}

 

 

MenuItem.PerformSelect 메서드
  //  menuItem1.PerformSelect();

  //menuItem1 의 Select 이벤트를 발생시킵니다.

15306 view

4.0 stars