【问题标题】:WindowsFormsApplicationBase doesn't exist in C# namespaces?C# 命名空间中不存在 WindowsFormsApplicationBase?
【发布时间】:2011-05-03 06:34:51
【问题描述】:
我读到 WindowsFormsApplicationBase 位于 Microsoft.VisualBasic.ApplicationServices 命名空间中
我真的必须添加成熟的 Microsoft.VisualBasic.ApplicationServices 才能在 c# 中获得 WindowsFormsApplicationBase 吗?如果我这样做,对我的 c# 应用程序的大小和性能有什么影响?
【问题讨论】:
标签:
c#
vb.net
winforms
performance
deployment
【解决方案2】:
要回答是否需要将 WindowsFormsApplicationBase 添加到 C# 程序的问题,不,您不需要。 C# 程序使用Application Class。 WindowsFormsApplicationBase 有单独可用的东西。例如,WindowsFormsApplicationBase 的 ApplicationContext 属性有一个 ApplicationContext 类实例,可以选择在 C# 中创建。
显然,WindowsFormsApplicationBase 旨在简化 VB.Net 表单应用程序,但它隐藏了在 C# 程序中更容易看到的内容。由 VS 生成的 C# 程序将具有类似于以下内容的 Main 方法:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
这基本上是除了 Form1 类之外的整个应用程序。在 VB.Net 中,该处理隐藏在 WindowsFormsApplicationBase 类中。 WindowsFormsApplicationBase.OnStartup 和 WindowsFormsApplicationBase.OnShutdown 方法在 C# 中完全没有必要,因为为 VB.Net 放入其中的代码可以简单地放入 C# Main 方法中。 WindowsFormsApplicationBase 类具有没有人需要的 DoEvents 方法,C# 程序员知道这一点。 WindowsFormsApplicationBase 类支持在 C# 中没有等效的启动屏幕,除了在 C# 中我们可以通过多种方式实现启动屏幕。