Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 WindowsFormsApplicationBase in c# ? What's the consequence on the size and performance of my c# app if I do so ?

like image 425
user310291 Avatar asked Nov 01 '10 04:11

user310291


2 Answers

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.

like image 193
Ani Avatar answered Nov 01 '22 13:11

Ani


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.

like image 24
user34660 Avatar answered Nov 01 '22 11:11

user34660