首页 > 解决方案 > 无法关闭此表单

问题描述

我运行一个新表格

static void Main()
       {
           Application.EnableVisualStyles();
           Application.SetCompatibleTextRenderingDefault(false);
           Application.Run(new FormMain());   
       }

然后我打电话给FormMain()

Application.Run(applicationContext);

如何FormMain通过代码关闭?

这里是FormMain

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using EasyTabs;

namespace CefSharp
{
    public partial class FormMain : Form
    {
        public static AppContainer Container = new AppContainer();


        public FormMain()
        {
            InitializeComponent();
            Container.Tabs.Add(new EasyTabs.TitleBarTab(Container)
            {
                Content = new frmTab
                {
                    Text = "New Tab"
                }
            });
            Container.SelectedTabIndex = 0;
            TitleBarTabsApplicationContext applicationContext = new TitleBarTabsApplicationContext();
            applicationContext.Start(Container);

            Application.Run(applicationContext);

            this.Hide();
            if(Container.ExitOnLastTabClose)
            { 
                this.Close();
            }

        }  
    }
}

标签: c#winforms

解决方案


您可以使用两种不同的方法:

  1. 如前所述,您可以使用formMain.Close()
  2. Application.Exit()完全关闭应用程序。

如果您想要更特别的东西,请使用 Bartek 解决方案。但是,你给我们的信息还不够


推荐阅读