打开其他表单后禁用按钮,然后在关闭其他表单后启用该按钮
问题描述:
如何在打开另一个表单后禁用按钮,然后在关闭其他表单后重新启用该按钮?看到我的代码如下。当我关闭第二个窗体时,按钮确实重新启用了而不是。我怎样才能解决这个问题?打开其他表单后禁用按钮,然后在关闭其他表单后启用该按钮
第一种形式:
private void llInfo_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
{
cls.aboutOpen();
llInfo.Enabled = false;
}
第二种形式:
private void btnClose_Click(object sender, EventArgs e)
{
login.llInfo.Enabled = true;
this.Close();
}
答
也许这会为你工作。所有的 首先,在第二种形式创建的Button
一个Property
的class
,即:
public Button myButton { get; set; }
现在在第一种形式的事件写:
private void llInfo_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
{
cls.aboutOpen();
cls.myButton = llInfo; //Referencing the button here
llInfo.Enabled = false;
}
然后在第二种形式的事件写:
private void btnClose_Click(object sender, EventArgs e)
{
myButton.Enabled = true; //Enabling the referenced button
this.Close();
}
不存在异常 –
存在空引用异常 –