当我需要访问嵌入式私有类中的类的私有成员时,我遇到了一种情况。我怎样才能有效地做到这一点。
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:我将控件动态添加到表单中,因此我可以确定在创建后它们已经订阅了此事件。