0
我使用多种窗体制作Windows窗体应用程序,我希望能够从任何窗体关闭整个应用程序。我的主要问题是在Program.cs
类中使用的System.Windows.Forms.Application
类是Private
。我希望任何表单能够直接使用它,如Program.Application.Exit();
。我意识到我可以在Program
类中创建一个ApplicationExit
方法,然后调用它,但这意味着如果我想使用Application
类中的任何其他方法,则需要创建一个新方法。从Windows窗体使用Application.Close()
这就是我现在所拥有的:
public static class Application
{
public static void EnableVisualStyles()
{
System.Windows.Forms.Application.EnableVisualStyles();
}
public static void Run()
{
System.Windows.Forms.Application.Run();
}
public static void Exit()
{
System.Windows.Forms.Application.Exit();
}
public static void SetCompatibleTextRenderingDefault(bool defaultValue)
{
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(defaultValue);
}
}
但有了这个,我需要单独添加每个方法,如果我想能够管理变量,我需要开始使用一吨{get; set;}
声明。这有效,但我想知道是否有一种方法可以在类Program
中直接继承或导入System.Windows.Forms.Application
类的类Application
。
您错了,System.Windows.Forms.Application类不是私有的(既不是Exit方法)。 。您可以随时拨打电话 –
谢谢。没有意识到调用Application.Exit();指的是整个应用程序,而不仅仅是特定的表单。 –