문제
임베디드 개인 수업에서 수업의 개인 회원에게 액세스 해야하는 상황이 있습니다. 어떻게 효율적으로 할 수 있습니까?
public partial class Form1 : Form
{
// this private label will be used only in this form
private class MyFormLabel : Label
{
MyFormLabel()
{
this.BorderStyle = BorderStyle.FixedSingle;
// ?? how to pass the from label_Click (without delegates)?
this.Click +=new EventHandler(????);
}
}
public Form1()
{
InitializeComponent();
}
private void label_Click(object sender, EventArgs e)
{
// displays the form caption
MessageBox.Show(this.Text);
}
}
NOTABENE : 컨트롤을 형태에 동적으로 추가하므로 창조 후에 이미이 이벤트에 구독되어 있는지 확인합니다.
해결책
중첩 클래스의 개인 수업 구성원에게 액세스 할 수 있습니다. 물론 인스턴스 메소드에 액세스하려면 여전히 클래스 인스턴스가 필요합니다.
다른 팁
이 경우, 그냥 주위에 오스위를하십시오. InitializeComponent()
do a myFormLabel.Click += label_Click
제휴하지 않습니다 StackOverflow