开发者

WindowsFormsApplicationBase doesn't exist in C# namespaces?

i read that WindowsFormsApplicationBase, is in the Microsoft.VisualBasic.ApplicationServices namespace

Do I have to really add the full-blown Microsoft.VisualBasic.ApplicationServices just to get WindowsFo开发者_StackOverflow中文版rmsApplicationBase in c# ? What's the consequence on the size and performance of my c# app if I do so ?


It's not as expensive as one might think. The WindowsFormsApplicationBase type is present in a framework assembly called Microsoft.VisualBasic.dll. All you have to do is make your project reference that assembly, and the type will be available to your application. You don't have to bundle this assembly with your application since it is included in .NET framework distributions, even when just the client profile is present.

So the only real 'cost' to using this class is loading the Microsoft.VisualBasic.dll assembly into your AppDomain at run-time, which should be negligible for a WinForms app, really.


To answer the question of whether you need to add WindowsFormsApplicationBase to a C# program, no you don't. A C# program uses the Application Class. The WindowsFormsApplicationBase has stuff that are available separately. For example, the ApplicationContext property of WindowsFormsApplicationBase has an ApplicationContext class instance that can optionally be created in C#.

Apparently the WindowsFormsApplicationBase is intended to simplify VB.Net forms applications but it hides things that would be easier to see in C# programs. A C# program, as generated by VS, will have a Main method similar to:

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

That is essentially the entire application except for the Form1 class. In VB.Net that processing is hidden in the WindowsFormsApplicationBase class. The WindowsFormsApplicationBase.OnStartup and WindowsFormsApplicationBase.OnShutdown methods are totally unnecessary in C# because the code that would be put in them for VB.Net can be simply put in the C# Main method. The WindowsFormsApplicationBase class has the DoEvents method that no one needs and C# programmers know that. WindowsFormsApplicationBase class has support of splash screens that there is no equivalent in C# except in C# we can implement splash screens in a variety of ways.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜