CHAPTER 19 (Frontpage web hosting) BUILDING A BETTER WINDOW WITH
CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.WINDOWS.FORMS 607 Building aMain Window by Hand To begin learning about Windows Forms programming, you ll build aminimal main window from scratch. Create a new folder on your hard drive (e.g., C:MyFirstWindow) and create a new file within this directory named MainWindow.cs using your editor of choice. In the world of Windows Forms, the Form class is used to represent any window in your application. This includes a topmost main window in a single-document interface (SDI) application, modeless and modal dialog boxes, and the parent and child windows of a multiple-document interface (MDI) application. When you are interested in creating and displaying the main window in your program, you have two mandatory steps: 1. Derive a new class from System.Windows.Forms.Form. 2. Configure your application s Main() method to invoke Application.Run(), passing an instance of your Form-derived type as an argument. Given this, update your MainWindow.cs file with the following class definition: using System; using System.Windows.Forms; namespace MyWindowsApp { public class MainWindow : Form { // Run this application and identify the main window. static void Main(string[] args) { Application.Run(new MainWindow()); } } } In addition to the always present mscorlib.dll, aWindows Forms application needs to reference the System.dll and System.Windows.Forms.dll assemblies. As you may recall from Chapter 2, the default C# response file (csc.rsp) instructs csc.exe to automatically include these assemblies during the compilation process, so you are good to go. Also recall that the /target:winexe option of csc.exe instructs the compiler to generate aWindows executable. Note Technically speaking, you can build a Windows application at the command line using the /target:exe option; however, if you do, you will find that a command window will be looming in the background (and it will stay there until you shut down the main window). When you specify /target:winexe, your executable runs as a native Windows Forms application (without the looming command window). To compile your C# code file, open a Visual Studio 2005 command prompt and issue the following command: csc /target:winexe *.cs Figure 19-1 shows a test run.
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.