关闭在任务栏属性中显示的表单设置为False。 [英] Closing a Form Whose Show in Taskbar property is set to False.

查看:115
本文介绍了关闭在任务栏属性中显示的表单设置为False。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用c#开发一个Windows应用程序。我打开了一个表单并单击表单1的按钮,我打开表单2,即打开表单1和表单2。任务栏属性中的Form2显示设置为false。我想在表单1的按钮点击事件中关闭或隐藏表单2.我尝试使用隐藏和关闭方法,但仍然显示表单2.

任何帮助!!!



在此先感谢!!!



I am developing a windows application using c#. I have one form open and on button click of form 1, I am opening form 2, i.e. both Forms form 1 and form 2 are opened. Form2 Show in task-bar property is set to false. I want to close or hide the form 2 on button click event of form 1. I tried to use Hide and Close Method, but the form 2 is still displayed.
Any Help !!!

Thanks In Advance !!!

bool Display; // declared at class level. 
//btnshow_hide is on form 1.
private void btnshow_hide_Click(object sender, EventArgs e)
        {
            form2 tc = new form2();
            if (Display == true)
            {
                Display = false;                
                tc.Show();
            }
            else if (Display == false)
            {
                Display = true;
                tc.Hide();
                //tc.Close();
            }
        }

推荐答案

您必须在表单的实际实例上使用表单的隐藏或关闭方法,而不是在新表单上使用:



You have to use the Hide or Close method of the form on the actual instance of the form, not on a new one:

private Form2 form2;
private void OpenForm2()
   {
   if (form2 == null)
      {
      form2 = new Form2();
      }
   form2.Show();
   }
private void CloseForm2()
   {
   if (form2 != null)
      {
      form2.Close();
      form2 = null;
      }
   }









< b>它无法正常工作。我在表单1上有按钮,我想使用相同的按钮来显示和隐藏表单2.



并不是一个很大的改变:





"Its not working. I have button on form 1, I want to use the same button to show and hide the form 2."

Not exactly a big change:

private Form2 form2;
private void ToggleForm2()
   {
   if (form2 == null)
      {
      form2 = new Form2();
      form2.Show();
      }
   else
      {
      form2.Close();
      form2 = null;
      }
   }


这篇关于关闭在任务栏属性中显示的表单设置为False。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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