2017-08-17 92 views
-1

如何在打開另一個表單後禁用按鈕,然後在關閉其他表單後重新啓用該按鈕?看到我的代碼如下。當我關閉第二個窗體時,按鈕確實重新啓用了而不是。我怎樣才能解決這個問題?打開其他表單後禁用按鈕,然後在關閉其他表單後啓用該按鈕

第一種形式:

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();  
} 
+0

不存在異常 –

+0

存在空引用異常 –

回答

0

也許這會爲你工作。所有的 首先,在第二種形式創建的Button一個Propertyclass,即:

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(); 
} 
相關問題