如何在form1到form2中启用按钮 [英] how to enable a button in form1 through form2

查看:128
本文介绍了如何在form1到form2中启用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

        private void button13_Click(object sender, EventArgs e)
        {

Form2 f2 = new Form2();
f2.show
button13.enable=false;

}




并以表格2



我想通过此事件启用按钮13





and in form 2



i want to enable the button 13 through this event


private void Form2_FormClosing(object sender, FormClosingEventArgs e)
        {

}







how to do it

推荐答案

按钮是否启用无关紧要,表单将关闭并将被处理.下次显示时,所有控件将处于默认状态
It doesn''t matter if the button is enabled or not, the form is closing and will be disposed of. The next time it is displayed all controls will be in default condition


最好的方法是让Form1处理Form2实例关闭并启用按钮:
The best way is to have the Form1 handle the Form2 instance closing, and enable the button:
private void button13_Click(object sender, EventArgs e)
   {
   button13.Enable=false;
   Form2 f2 = new Form2();
   f2.FormClosing += new FormClosingEventHandler(f2_FormClosing);
   f2.Show();
   }

private void f2_FormClosing(object sender, FormClosingEventArgs e)
   {
   button13.Enable = true;
   }


在表单1中,处理form2关闭事件并在那里更改启用状态.如果需要,在2中设置某种指示,表示应该启用/禁用form1中的按钮,然后检查form1中的值,如下所示:

In form 1, handle the form2 closing event and change the enabled status there. If you need to, set some sort of indication in for 2 that the button in form1 should be enabled/disabled, and check that value in form1, something like this:

private void Form2_Closing(...)
{
    Form2 form = sender as Form2;
    if (form.SomeValue == true)
    {
        button13.Enabled = true;
    }
}


这篇关于如何在form1到form2中启用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆