Rv diaz Rv diaz - 5 months ago 21
C# Question

Disable a button when opening other form, then enable that button after closing other form

How can I disable a button after I open another form and then re-enable that button after I close the other form? See my code below. When I close the second form, the button does not become re-enabled. How can I fix this?

First form:

private void llInfo_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
{
cls.aboutOpen();
llInfo.Enabled = false;
}


Second form:

private void btnClose_Click(object sender, EventArgs e)
{
login.llInfo.Enabled = true;
this.Close();
}

Answer Source

Maybe this would work for you. First of all, create a Property of Button in second form's class, ie:

public Button myButton { get; set; }

Now in the first form's event write this:

private void llInfo_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
{
    cls.aboutOpen();
    cls.myButton = llInfo; //Referencing the button here
    llInfo.Enabled = false;
}

Then in the second form's event write:

private void btnClose_Click(object sender, EventArgs e)
{ 
   myButton.Enabled = true; //Enabling the referenced button
   this.Close();
}