如何关闭Windows窗体? [英] how to close windows forms ?

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

问题描述

大家好,

我在Windows应用程序中设计了两种形式,第一种是登录"形式,第二种是主要"形式.成功登录后,我想关闭登录"表单,并显示另一个表单(主表单).登录完成后如何关闭!

谢谢和问候!
Murali

解决方案

通常通过登录对话框完成,例如,参见: [ // 隐藏当前表单. .Hide(); // 创建了一个GetNotificaiton From对象. MainForm showNotification = MainForm(); // 显示GetnNotificaiton发件人. showNotification.Show();



要显示表单,只需编写对象名称dot(.)show().
像这样的objMainForm.Show();


你好,

解决方案1:
简单的方法是隐藏登录表单.

 私有  void  button1_Click(对象发​​件人,EventArgs e)
       {
           Form2 obj =  Form2();
           obj.Show();
            .Hide();
       } 



解决方案2:
修改Program.cs文件

静态类Program
   {
       ///<  摘要 > 
       ///应用程序的主要入口点.
       ///<  /summary  > 
       [STAThread]
       静态void Main()
       {
           Application.EnableVisualStyles();
           Application.SetCompatibleTextRenderingDefault(false);
           如果(new Login().ShowDialog()!= DialogResult.OK)
           {
               Application.Run(新Form2());
           }
       }
   } 


希望这对您有帮助...
谢谢!!!


Hi all,

I have designed two forms in windows application, 1st one is "login" form and 2nd one is "Main" form. When i login successful i want to close the "login" form and i want to display the another form (Main form). How to close that when login is completed !

Thanks and Regards!
Murali

Usually that is accomplished with a login dialog, see, for instance: "C#: How to prevent main form from showing too early"[^] at Stack Overflow.


//Hide the current Form.
this.Hide();
//Created an object of GetNotificaiton From.
MainForm showNotification = new MainForm();
//show the GetnNotificaiton From.
showNotification.Show();



To show a form just write the object name dot(.) show().
like this objMainForm.Show();


Hello,

Solution1:
Simple way to do this is to hide the login form.

private void button1_Click(object sender, EventArgs e)
       {
           Form2 obj = new Form2();
           obj.Show();
           this.Hide();
       }



Solution 2:
Modify Program.cs file

static class Program
   {
       /// <summary>
       /// The main entry point for the application.
       /// </summary>
       [STAThread]
       static void Main()
       {
           Application.EnableVisualStyles();
           Application.SetCompatibleTextRenderingDefault(false);
           if (new Login().ShowDialog() != DialogResult.OK)
           {
               Application.Run(new Form2());
           }
       }
   }


Hope this will help you...
Thanks!!!


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

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