By Pavel Tsekov
Some interesting static properties of the Application class.
Let's have a look at some of the properties in the Application class,
which in part of the System.Windows.Forms namespace.
Application.StartupPath - returns a string value which represents the
path to the starting directory of an application
(for ex. "C:\Program Files\MyApp")
Application.ExecutablePath - returns a string value which represents the
path to the starting directory of an application, concatenated with the executable
file of the same application
(for ex. "C:\Program Files\MyApp\MyApp.exe")
Application.CompanyName - returns a string value, representing name of the company, which
develops the application. In C# this name is the name of outermost namespace of the starting
method Main().
(for ex. if we have the following code:
using System;
using System.Windows.Forms;
namespace A
{
namespace B
{
class MainForm : Form
{
public MainForm() //constructor
{
this.Text="Form name: "+"Form1; ";
this.Text=this.Text+"Company Name: "+Application.CompanyName;
}
public static void Main() //starting point
{
Application.Run(new MainForm());
}
}
}
}
)
In case we hadn't put any namespace around our Main() function, the Application.CompanyName returns
the name of the class of the starting form as a name of the company.
(for ex.: Here in this example the Application.CompanyName="MainForm"
using System;
using System.Windows.Forms;
class MainForm : Form
{
public MainForm() //constructor
{
this.Text="Form name: "+"Form1; ";
this.Text=this.Text+"Company Name: "+Application.CompanyName;
}
public static void Main() //starting point
{
Application.Run(new MainForm());
}
}
)