c# - 无法关闭此表单
问题描述
我运行一个新表格
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();
}
}
}
}
解决方案
您可以使用两种不同的方法:
- 如前所述,您可以使用
formMain.Close()
- 并
Application.Exit()
完全关闭应用程序。
如果您想要更特别的东西,请使用 Bartek 解决方案。但是,你给我们的信息还不够
推荐阅读
- c++ - 使用 istream 提取运算符解析 csv:如何检测缺失的字段值?
- python - 评估机器学习文本分类器
- python - pandas 将列类型更改为 datetime afterr group by
- db2 - 我可以编写一个只需要不匹配部分的 PCRE 条件吗?
- javascript - 在 React 中单击按钮时调用 Api post 方法
- r - 如何使用 r 中的 igraph 编写代码,将特定颜色和线型分配给网络中的边缘属性
- python - 如何创建一个列,将列中的所有值分组到列表中,该列表位于熊猫中不同列的值之间
- reactjs - React-Moment- 将 ISO 8601 剩余时间解析为可读格式
- vba - 检查电子邮件地址是否启用了自动回复 (OOF)
- php - PHP : 继续让我出去