我需要更改按钮单击时标签的文本,但它不起作用并给我运行时错误。我有单独的标签类和单独的按钮。这是虚拟代码。真正的代码包含位置和大小标签和按钮。一切都是动态创建的。谢谢!
/-------------------------------------LABEL class-------------------------------/
private Label label1;
public Label getLabel1()
{
return label1;
}
public LABEL()
{
label1 = new Label();
}
public void print()
{
label1.Text = "x";
Controls.Add(label1);
}//
/-------------------------------------BUTTON class----------------------------------/
private Button button1;
public BUTTON()
{
}
public void print()
{
button1 = new Button();
button1.Click +=new EventHandler(button1_Click);
Controls.Add(button1);
}
public void button1_Click(object sender, EventArgs e)
{
LABEL label = new LABEL();
label.getLabel1().Text = "y";
}