打开和关闭表单,表单在任务栏C#中多次显示 [英] Opening and closing forms, form shows multiple times in taskbar C#

查看:113
本文介绍了打开和关闭表单,表单在任务栏C#中多次显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个c#winforms项目,其中包含3种形式的Splash表单,Login表单和Menu表单。 Startup from当然是Spash。用户将按下按钮移动到登录表单,然后按此按钮进入菜单。


问题是,即使程序正在执行此操作,但它显示多次任务栏,我不再确定我是否正确关闭表格或我犯了错误


我已经在微软onedrive上传了一个示例项目  此处


M y program.cs

命名空间TestProject 
{
静态类程序
{
///< summary>
///应用程序的主要入口点。
///< / summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormSplash());
}
}
}

我的splash.cs代码

 namespace TestProject 
{
public partial class FormSplash:System.Windows.Forms.Form
{
public FormSplash()
{
InitializeComponent();
}
private void BtnProceedToLogIn_Click(object sender,EventArgs e)
{
FormLogin myLogIn = new FormLogin();
myLogIn.ShowDialog();

this.Close();
}
}
}

我的Login.cs


< pre class ="prettyprint"> namespace TestProject
{
public partial class FormLogin:System.Windows.Forms.Form
{
public FormLogin()
{
InitializeComponent();
}
private void BtnProceedToMenu_Click(object sender,EventArgs e)
{
FormMenu myMenu = new FormMenu();
myMenu.ShowDialog();
this.Close();
}
}
}

这是菜单表格打开时所有其他的表格已关闭。我的问题是当只有菜单打开时,如何在任务栏中打开3页。有什么我能做的,只有一页显示而不是三个这样的




 


如果您认为可以实现它

解决方案

您使用ShowDialog方法。调用此方法时,直到关闭对话框后才会执行其后面的代码。这意味着当模态窗口关闭时调用this.Close()方法。


I have a c# winforms project which has 3 forms the Splash form , the Login form and the Menu form. the Startup from is the Spash of course. the user will press a button to move to the Login form and the after that proceed to the menu.

The problem is that even though the program is doing this but it is showing multiple time in the taskbar, I am no longer sure if i am closing the forms right or i am making a mistake

I have uploaded a sample project in the microsoft onedrive here

My program.cs

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

My splash.cs code

namespace TestProject
{
    public partial class FormSplash :System.Windows.Forms.Form
    {
        public FormSplash()
        {
            InitializeComponent();  
        }    
        private void BtnProceedToLogIn_Click(object sender, EventArgs e)
        {
            FormLogin myLogIn = new FormLogin();
            myLogIn.ShowDialog();

            this.Close();
        }
    }
}

My Login.cs

namespace TestProject
{
    public partial class FormLogin : System.Windows.Forms.Form
    {
        public FormLogin()
        {
            InitializeComponent();
        }
        private void BtnProceedToMenu_Click(object sender, EventArgs e)
        {
            FormMenu myMenu = new FormMenu();
            myMenu.ShowDialog();
            this.Close();
        }        
    }
}

And this is when the menu form is open and all the other forms are closed. My question is how come 3 pages are open in the Taskbar when only the menu is open. is there something i can do so that only one page shows instead of three like this

 

If you think it you can achieve it

解决方案

You use ShowDialog method. When this method is called, the code following it is not executed until after the dialog box is closed. It means this.Close() method is called when modal window is closed.


这篇关于打开和关闭表单,表单在任务栏C#中多次显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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