开发者

Enabling button of one form another forms button click

开发者 https://www.devze.com 2023-04-09 13:17 出处:网络
I have form1 and form2 running at the same time . The flow is as below 1) Cl开发者_开发技巧ick form1 button

I have form1 and form2 running at the same time .

The flow is as below

1) Cl开发者_开发技巧ick form1 button
2) disable form1 button
3) show form2 ( form 1 is not closed)
4) click form 2 button 
5) close form 2
6) enable form1 button 

I have done till 5th step . Couldn't do 6th . Can anyone help ?


You're right - creating another copy of Form1 is not the right way to go.

It's not very clear from your question, but it sounds like you want to re-enable the same button that you disabled before opening Form2. In that case, you can listen to Form2's FormClosed event and handle it in Form1:

public class Form1 : Form
{
    public void ShowForm2()
    {
        myButton.Enabled = false;
        var f2 = new Form2();
        f2.FormClosed += HandleForm2Closed;
        f2.Show();
    }

    private void HandleForm2Closed(Object sender, FormClosedEventArgs e)
    {
        myButton.Enabled = true;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号