[英]Where is the Winforms "application framework" in C# that exists in VB.NET?
I've developed VB.NET Winforms projects in the past that use the "Windows Application Framework" settings, which are found on the "Application" tab in the project properties:我过去开发过使用“Windows 应用程序框架”设置的 VB.NET Winforms 项目,这些设置位于项目属性的“应用程序”选项卡上:
One particularly useful feature of this is the ability to make a single-instance application with one click of a checkbox.其中一个特别有用的功能是只需单击一下复选框即可创建单实例应用程序。 This works very well.
这非常有效。 Here is the C# project properties for a Winforms project:
这是 Winforms 项目的 C# 项目属性:
There's nothing about the application framework, neither on the "Application" tab nor elsewhere.无论是在“应用程序”选项卡还是其他地方,都没有关于应用程序框架的任何内容。 All the references I've found to "single instance" applications talk about using a custom solution with a mutex.
我发现的所有“单实例”应用程序的参考资料都谈到使用带有互斥锁的自定义解决方案。 I can't find any information about why there is no equivalent application framework in C# projects.
我找不到有关为什么 C# 项目中没有等效应用程序框架的任何信息。 Can anyone shed some light on this?
任何人都可以对此有所了解吗?
These properties are exclusively available in VB.Net project types.这些属性仅在 VB.Net 项目类型中可用。 If you want to utilize these VB.Net properties in C# project then you need to add reference to
Microsoft.VisualBasic
assembly and create your custom App class inherited from Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
to access the protected members that appears in the project properties and run your windows form application via your custom app class instead of C# Application class methods.如果要在 C# 项目中使用这些 VB.Net 属性,则需要添加对
Microsoft.VisualBasic
程序集的引用并创建从Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
继承的自定义 App 类,以访问出现在项目属性中的受保护成员并通过自定义应用程序类而不是 C# 应用程序类方法运行 Windows 窗体应用程序。
static class Program
{
[STAThread]
static void Main(string[] args)
{
var app = new MyApp(new Form1());
app.Run(args);
}
}
internal class MyApp : Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
{
public MyApp(Form mainForm)
{
this.EnableVisualStyles = true;
this.SaveMySettingsOnExit = true;
this.IsSingleInstance = true;
this.MainForm = mainForm;
}
}
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
provides predefined features to an winform application that are only available via VB.Net. Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
为 winform 应用程序提供了预定义的功能,这些功能只能通过 VB.Net 使用。 There many predefined class libraries in Microsoft.VisualBasic
assembly that are not available in C#. Microsoft.VisualBasic
程序集中有许多 C# 中不可用的预定义类库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.