Buttons Enabled Property not Working Properly

.net, button, c#, properties, winforms

Solution

SOLUTION You should never disable a button, or change it´s visibility before it is initialized, otherwise you won't be able to enable it again, or turn it visible again. Instead, you should disable it on it's own "Initialized" event, and then it will work properly! I had the same problem.

Problem

I am creating an Windows Application. I have two buttons. I have written the following code snippet. ``` frmRb obj = new frmrb(); private void btnPd_Click(object sender, EventArgs e) { btnCancel.Enabled = true; obj.btnRtn.Enabled = true; } private void btnCancel_Click(object sender, EventArgs e) { this.Close(); obj.BringToFront(); obj.Focus(); } ``` The above coding does not generate any error. All the statements are working properly but the following statement is not working properly: obj.btnRtn.Enabled = true; is not executed. The frmrb forms is bring to front and it is focussed but btnRtn is not Enabled that is the statement obj.btnRtn.Enabled = true; is not working. By default I have set the property of btnRtn Enabled to false. And Please note the Modifier property of btnRtn button is set to PUBLIC. Now how should I change the coding so that I can get this statement executed. obj.btnRtn.Enabled = true; Can anybody help me out? Thanks in Advance!!

Original source