如何关闭VC中的表单# [英] How to close a form in VC#

查看:86
本文介绍了如何关闭VC中的表单#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正准备在VC#中编写一个小窗口程序,其中我准备了一些表格。现在我的问题是我不知道如何关闭这些表格。



我正在尝试以下代码但没有成功:

 1。 this.hide(); //此代码隐藏了表单,但在后台继续工作。 
2. this.close(); //此代码退出完整程序
3.application.exit(); //此代码也退出完整的程序。



我想要的是当我点击一个按钮时,只有那个特定的表格被关闭。



感谢您的帮助!!!!

解决方案

引用:
2。 this.close(); //此代码退出完整程序



否,如果是主窗体,则代码退出整个程序(如果这个不是主要形式,那么特定表格将被关闭)。如果要在表单关闭后执行某些代码,请转到Program.cs文件,然后尝试:

  static   class 计划
{
/// < span class =code-comment> < summary >
/// 应用程序的主要入口点。
/// < / summary >
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault( false );

Application.Run( new Form1());在Program.cs文件中, // ,它可能是另一个名称而不是Form1
// 在此处添加您希望在表单关闭后执行的代码

}
}



如果你没有在 Application.Run 行,如果主窗体关闭,那么什么都不会执行,然后应用程序关闭。



另外,C#是区分大小写的,所以不要使用 this.close(),但是 this.Close(),也可以使用。隐藏()而不是 this.hide(),并使用 Application.Exit()而不是 application.exit()



希望这会有所帮助。


Hi


只需使用name_of_form.Close()eg- form1.close()


正如您在示例中所给出的那样

th is.close();

C#是一种区分大小写的语言。您在代码close();中使用了小写字母,这可能是您收到somme错误的原因。
只需使用: -

这个。关闭();

Hi all,

I am preparing a small windows program in VC# in which I have prepared a few forms. Now my problem is I don''t know how to close these forms.

I am trying the below code with no success:

1. this.hide(); // this code hides the form, but in background it keeps working.
2. this.close(); // this code exits the complete program
3.application.exit();  // this code also exits the complete program.


What I want is when I click on a button, only that particular form gets closed.

Thank you for your help!!!!

解决方案

Quote:

2. this.close(); // this code exits the complete program


No, if this is the main form, then the code exits the complete program (if this isn''t the main form, then the particular form will be closed). If you want to execute some code after the form is closed, then go to your Program.cs file, and try this:

static class Program
   {
       /// <summary>
       /// The main entry point for the application.
       /// </summary>
       [STAThread]
       static void Main()
       {
           Application.EnableVisualStyles();
           Application.SetCompatibleTextRenderingDefault(false);

           Application.Run(new Form1()); // in your Program.cs file, it may be another name than Form1
           // add HERE your code which you want to execute after your form is closed

       }
   }


If you don''t add code after the Application.Run line, then nothing will be executed if the main form is closed, and then the application closes.

Also, C# is case-sensitive, so don''t use this.close(), but this.Close(), also use this.Hide() instead of this.hide(), and use Application.Exit() instead of application.exit().

Hope this helps.


Hi
Just use name_of_form.Close() eg- form1.close()


As you have given in your example
this.close();
C# is a case sensitive language. You used a lower case in your code "close();", it may be the reason why you are getting somme errors.
Just use this:-
this.Close();


这篇关于如何关闭VC中的表单#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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