CHAPTER 19 BUILDING A BETTER WINDOW WITH (Remote web server)

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.WINDOWS.FORMS 609 The Role of the Application Class The Application class defines numerous static members that allow you to control various low-level behaviors of aWindows Forms application. For example, the Application class defines a set of events that allow you to respond to events such as application shutdown and idle-time processing. In addition to the Run() method, here are some other methods to be aware of: DoEvents(): Provides the ability for an application to process messages currently in the message queue during a lengthy operation. Exit(): Terminates the Windows application and unloads the hosting AppDomain. EnableVisualStyles(): Configures your application to support Windows XP visual styles. Do note that if you enable XP styles, this method must be called before loading your main window via Application.Run(). The Application class also defines a number of properties, many of which are read-only in nature. As you examine Table 19-2, note that most of these properties represent an application-level trait such as company name, version number, and so forth. In fact, given what you already know about assembly-level attributes (see Chapter 12), many of these properties should look vaguely familiar. Table 19-2. Core Properties of the Application Type Property Meaning in Life CompanyName Retrieves the value of the assembly-level [AssemblyCompany] attribute ExecutablePath Gets the path for the executable file ProductName Retrieves the value of the assembly-level [AssemblyProduct] attribute ProductVersion Retrieves the value of the assembly-level [AssemblyVersion] attribute StartupPath Retrieves the path for the executable file that started the application Finally, the Application class defines various static events, some of which are as follows: ApplicationExit: Occurs when the application is just about to shut down Idle: Occurs when the application s message loop has finished processing the current batch of messages and is about to enter an idle state (as there are no messages to process at the current time) ThreadExit: Occurs when a thread in the application is about to terminate Fun with the Application Class To illustrate some of the functionality of the Application class, let s enhance your current MainWindow to perform the following: Reflect over select assembly-level attributes. Handle the static ApplicationExit event. The first task is to make use of select properties in the Application class to reflect over some assembly-level attributes. To begin, add the following attributes to your MainWindow.cs file (note you are now using the System.Reflection namespace): using System; using System.Windows.Forms; using System.Reflection;
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Leave a Reply