CHAPTER 19 BUILDING A BETTER WINDOW WITH (Web design programs)

May 22nd, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.610 STEM.WINDOWS.FORMS Figure 19-2. Reading attributes via the Application type // Some attributes regarding this assembly. [assembly:AssemblyCompany(”Intertech Training”)] [assembly:AssemblyProduct(”A Better Window”)] [assembly:AssemblyVersion(”1.1.0.0″)] namespace MyWindowsApp { … } Rather than manually reflecting over the [AssemblyCompany] and [AssemblyProduct] attributes using the techniques illustrated in Chapter 12, the Application class will do so automatically using various static properties. To illustrate, implement the default constructor of MainForm as so: public class MainWindow : Form { public MainWindow() { MessageBox.Show(Application.ProductName, string.Format(”This app brought to you by {0}”, Application.CompanyName)); } } When you run this application, you ll see amessage box that displays various bits of information (see Figure 19-2). Now, let s equip this Form to respond to the ApplicationExit event. When you wish to respond to events from within aWindows Forms application, you will be happy to find that the same event syntax detailed in Chapter 8 is used to handle GUI-based events. Therefore, if you wish to intercept the static ApplicationExit event, simply register an event handler using the += operator: public class MainForm : Form { public MainForm() { … // Intercept the ApplicationExit event. Application.ApplicationExit += new EventHandler(MainWindow_OnExit); } private void MainWindow_OnExit(object sender, EventArgs evArgs) { MessageBox.Show(string.Format(”Form version {0} has terminated.”, Application.ProductVersion)); } }
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

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

May 21st, 2008

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.

CHAPTER 19 (Mac os x web server) BUILDING A BETTER WINDOW WITH

May 7th, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.608 STEM.WINDOWS.FORMS Figure 19-1. A simple main window la Windows Forms Granted, the Form is not altogether that interesting at this point. But simply by deriving from Form, you have a minimizable, maximizable, resizable, and closable main window (with a default system-supplied icon to boot!). Unlike other Microsoft GUI frameworks you may have used in the past (Microsoft Foundation Classes, in particular), there is no need to bolt in hundreds of lines of coding infrastructure (frames, documents, views, applications, or message maps). Unlike a C-based Win32 API Windows application, there is no need to manually implement WinProc() or WinMain() procedures. Under the .NET platform, those dirty details have been encapsulated within the Form and Application types. Honoring the Separation of Concerns Currently, the MainWindow class defines the Main() method directly within its scope. If you prefer, you may create a second static class (I named mine Program) that is responsible for the task of launching the main window, leaving the Form-derived class responsible for representing the window itself: namespace MyWindowsApp { // The main window. public class MainWindow : Form { } // The application object. public static class Program { static void Main(string[] args) { // Don’t forget to ‘use’ System.Windows.Forms! Application.Run(new MainWindow()); } } } By doing so, you are abiding by an OO principal termed the separation of concerns. Simply put, this rule of OO design states that a class should be in charge of doing the least amount of work possible. Given that you have refactored the initial class into two unique classes, you have decoupled the Form from the class that creates it. The end result is amore portable window, as it can be dropped into any project without carrying the extra baggage of a project-specific Main() method. Source Code The MyFirstWindow project can be found under the Chapter 19 subdirectory.
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

CHAPTER 19 (Frontpage web hosting) BUILDING A BETTER WINDOW WITH

May 6th, 2008

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.

CHAPTER 19 BUILDING (Web hosting providers) A BETTER WINDOW WITH

May 5th, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.606 STEM.WINDOWS.FORMS Given that the total number of types within System.Windows.Forms is well over 100 strong, it would be redundant (not to mention a terrible waste of paper) to list every member of the Windows Forms family. To set the stage for the next several chapters, however, Table 19-1 lists some of the core .NET 2.0 System.Windows.Forms types (consult the .NET Framework 2.0 SDK documentation for full details). Table 19-1. Core Types of the System.Windows.Forms Namespace Classes Meaning in Life Application This class encapsulates the runtime operation of aWindows Forms application. Button, CheckBox, ComboBox, These classes (in addition to many others) correspond to DateTimePicker, ListBox, various GUI widgets. You ll examine many of these items in LinkLabel, MaskedTextBox, detail in Chapter 21. MonthCalendar, PictureBox, TreeView FlowLayoutPanel, .NET 2.0 now supplies various layout managers that TableLayoutPanel automatically arrange a Form s controls during resizing. Form This type represents amain window, dialog box, or MDI child window of aWindows Forms application. ColorDialog, OpenFileDialog, These are various standard dialog boxes for common GUI SaveFileDialog, FontDialog, operations. PrintPreviewDialog, FolderBrowserDialog Menu, MainMenu, MenuItem, These types are used to build topmost and context- ContextMenu, MenuStrip, sensitive menu systems. The new (.NET 2.0) MenuStrip and ContextMenuStrip, ContextMenuStrip controls allow you to build menus that may contain traditional drop-down menu items as well as other controls (text boxes, combo boxes, and so forth). StatusBar, Splitter, ToolBar, These types are used to adorn a Form with common child ScrollBar, StatusStrip, ToolStrip controls. Note In addition to System.Windows.Forms, the System.Windows.Forms.dll assembly defines additional GUI-centric namespaces. For the most part, these additional types are used internally by the Forms engine and/or the designer tools of Visual Studio 2005. Given this fact, we will keep focused on the core System.Windows.Forms namespace. Working with the Windows Forms Types When you build aWindows Forms application, you may choose to write all the relevant code by hand (using Notepad or TextPad, perhaps) and feed the resulting *.cs files into the C# compiler using the /target:winexe flag. Taking time to build some Windows Forms applications by hand not only is a great learning experience, but also helps you understand the code generated by the various graphics designers found within various .NET IDEs. To make sure you truly understand the basic process of building aWindows Forms application, the initial examples in this chapter will avoid the use of graphics designers. Once you feel comfortable with the process of building aWindows Forms application wizard-free, you will then leverage the various designer tools provided by Visual Studio 2005.
We recommend high quality webhost to host and run your jsp application: christian web host services.

Anonymous web server - Building a Better Window with System.Windows.Forms If you

May 4th, 2008

Building a Better Window with System.Windows.Forms If you have read through the previous 18 chapters, you should have a solid handle on the C# programming language as well as the foundation of the .NET architecture. While you could take your newfound knowledge and begin building the next generation of console applications (boring!), you are more likely to be interested in building an attractive graphical user interface (GUI) to allow users to interact with your system. This chapter is the first of three aimed at introducing you to the process of building traditional form-based desktop applications. Here, you ll learn how to build a highly stylized main window using the Form and Application classes. This chapter also illustrates how to capture and respond to user input (i.e., handle mouse and keyboard events) within the context of a GUI desktop environment. Finally, you will learn to construct menu systems, toolbars, status bars, and multiple-document interface (MDI) applications, both by hand and using the designers incorporated into Visual Studio 2005. Overview of the System.Windows.Forms Namespace Like any namespace, System.Windows.Forms is composed of various classes, structures, delegates, interfaces, and enumerations. Although the difference in appearance between a console UI (CUI) and graphical UI (GUI) seems at first glance like night and day, in reality the process of building aWindows Forms application involves nothing more than learning how to manipulate a new set of types using the C# syntax you already know. From a high level, the hundreds of types within the System.Windows.Forms namespace can be grouped into the following broad categories: Core infrastructure: These are types that represent the core operations of a .NET Forms program (Form, Application, etc.) and various types to facilitate interoperability with legacy ActiveX controls. Controls: These are types used to create rich UIs (Button, MenuStrip, ProgressBar, DataGridView, etc.), all of which derive from the Control base class. Controls are configurable at design time and are visible (by default) at runtime. Components: These are types that do not derive from the Control base class but still provide visual features to a .NET Forms program (ToolTip, ErrorProvider, etc.). Many components (such as the Timer) are not visible at runtime, but can be configured visually at design time. Common dialog boxes: Windows Forms provides a number of canned dialog boxes for common operations (OpenFileDialog, PrintDialog, etc.). As you would hope, you can certainly build your own custom dialog boxes if the standard dialog boxes do not suit your needs. 605 C H A P T E R 1 9
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

Web proxy server - CHAPTER 18 604 THE .NET REMOTING LAYER

May 3rd, 2008

CHAPTER 18 604 THE .NET REMOTING LAYER Source Code The AsyncWKOCarProviderClient project is located under the Chapter 18 subdirectory. The Role of the [OneWay] Attribute Imagine that your CarProvider has a new method named AddCar(), which takes a JamesBondCar input parameter and returns nothing. The key point is that it returns nothing. As you might assume given the name of the System.Runtime.Remoting.Messaging.OneWayAttribute class, the .NET remoting layer passes the call to the remote one-way method, but does not bother to set up the infrastructure used to return a given value (hence the name one-way). Here is the update: // Home of the [OneWay] attribute. using System.Runtime.Remoting.Messaging; … namespace CarGeneralAsm { public class CarProvider : MarshalByRefObject { … // The client can ‘fire and forget’ when calling this method. [OneWay] public void AddCar(JamesBondCar newJBC) { theJBCars.Add(newJBC);} } } Callers would invoke this method directly as always: // Make the car provider. CarProvider cp = new CarProvider(); // Add a new car. cp.AddCar(new JamesBondCar(”Zippy”, 200, false, false)); From the client s point of view, the call to AddCar() is completely asynchronous, as the CLR will ensure that a background thread is used to remotely trigger the method. Given that AddCar() has been decorated with the [OneWay] attribute, the client is unable to obtain any return value from the call. Because AddCar() returns void, this is not an issue. In addition to this restriction, also be aware that if you have a [OneWay] method that defines output or reference parameters (via the out or ref keyword), the caller will not be able to obtain the callee s modification(s). Furthermore, if the [OneWay] method happens to throw an exception (of any type), the caller is completely oblivious of this fact. In a nutshell, remote objects can mark select methods as [OneWay] to allow the caller to employ a fire-and-forget mentality. Summary In this chapter, you examined how to configure distinct .NET assemblies to share types between application boundaries. As you have seen, a remote object may be configured as an MBV or MBR type. This choice ultimately controls how a remote type is realized in the client s application domain (a copy or transparent proxy). If you have configured a type to function as an MBR entity, you are suddenly faced with a number of related choices (WKO versus CAO, single call versus singleton, and so forth), each of which was addressed during this chapter. As well, you examined the process of tracking the lifetime of a remote object via the use of leases and lease sponsorship. Finally, you revisited of the role of the .NET delegate type to understand how to asynchronously invoke a remote method (which, as luck would have it, is identical to the process of asynchronously invoking a local type).
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Web site hosting - CHAPTER 18 THE .NET REMOTING LAYER 603

May 2nd, 2008

CHAPTER 18 THE .NET REMOTING LAYER 603 the first step is to define a custom delegate to represent the remote method in question. At this point, the caller can make use of any of the techniques seen in Chapter 14 to invoke and receive the method return value. By way of a simple illustration, create a new console application (AsyncWKOCarProviderClient) and set a reference to the first iteration of the CarGeneralAsm.dll assembly. Now, update the Program class as so: class Program { // The delegate for the GetAllAutos() method. internal delegate List GetAllAutosDelegate(); static void Main(string[] args) { Console.WriteLine(”Client started! Hit enter to end”); RemotingConfiguration.Configure (”AsyncWKOCarProviderClient.exe.config”); // Make the car provider. CarProvider cp = new CarProvider(); // Make the delegate. GetAllAutosDelegate getCarsDel = new GetAllAutosDelegate(cp.GetAllAutos); // Call GetAllAutos() asynchronously. IAsyncResult ar = getCarsDel.BeginInvoke(null, null); // Simulate client-side activity. while(!ar.IsCompleted) { Console.WriteLine(”Client working…”); } // All done! Get return value from delegate. List allJBCs = getCarsDel.EndInvoke(ar); // Use all cars in List. foreach(JamesBondCar j in allJBCs) UseCar(j); Console.ReadLine(); } } Notice how the client application first declares a delegate that matches the signature of the GetAllAutos() method of the remote CarProvider type. When the delegate is created, you pass in the name of the method to call (GetAllAutos), as always. Next, you trigger the BeginInvoke() method, cache the resulting IAsyncResult interface, and simulate some work on the client side (recall that the IAsyncResult.IsCompleted property allows you to monitor if the associated method has completed processing). Finally, once the client s work has completed, you obtain the List<> returned from the CarProvider.GetAllAutos() method by invoking the EndInvoke() member, and pass each JamesBondCar into a static helper function named UseCar(): public static void UseCar(JamesBondCar j) { Console.WriteLine(”Can car fly? {0}”, j.isFlightWorthy); Console.WriteLine(”Can car swim? {0}”, j.isSeaWorthy); } Again, the beauty of the .NET delegate type is the fact that the logic used to invoke remote methods asynchronously is identical to the process of local method invocations.
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

CHAPTER 18 602 THE .NET REMOTING LAYER (Web site counters)

May 1st, 2008

CHAPTER 18 602 THE .NET REMOTING LAYER 1. On your hard drive, create a new folder to hold your CarGeneralAsm.dll. Within this folder, create a subdirectory named Bin. Now, copy the CarGeneralAsm.dll to this subdirectory (e.g., C:IISCarServiceBin). 2. Open the Internet Information Services applet on the host machine (located under the Administrative Tools folder in your system s Control Panel). 3. Right-click the Default Web Site node and select New .Virtual Directory. 4. Create a virtual directory that maps to the root folder you just created (C:IISCarService). The remaining default settings presented by the New Virtual Directory Wizard are fine. 5. Finally, create a new configuration file named web.config to control how this virtual directory should register the remote type (see the following code). Make sure this file is saved under the root folder (in this example, C:IISCarService). Now that your CarGeneralAsm.dll has been configured to be reachable via HTTP requests under IIS, you can update your client-side *.config file as follows (using the name of your IIS host, of course): At this point, you are able to run your client application as before. Asynchronous Remoting To wrap things up, let s examine how to invoke members of a remote type asynchronously. In Chapter 14, you were first introduced to the topic of asynchronous method invocations using delegate types. As you would expect, if a client assembly wishes to call a remote object asynchronously,
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Web proxy server - CHAPTER 18 THE .NET REMOTING LAYER 601

April 30th, 2008

CHAPTER 18 THE .NET REMOTING LAYER 601 Figure 18-10. The Windows Services applet That s it! Now compile your project. Installing the CarWinService Installing CarService.exe on a given machine (local or remote) requires two steps: 1. Move the compiled service assembly (and any necessary external assemblies; CarGeneralAsm. dll in this example) to the remote machine. 2. Run the installutil.exe command-line tool, specifying your service as an argument. Assuming step 1 is complete, open a Visual Studio 2005 command window, navigate to the location of the CarWinService.exe assembly, and issue the following command (note that this same tool can be used to uninstall a service as well): installutil carwinservice.exe Once this Windows service has been properly installed, you are now able to start and configure it using the Services applet, which is located under the Administrative Tools folder of your system s Control Panel. Once you have located your CarService (see Figure 18-10), click the Start link to load and run the binary. Source Code The CarWinService project is located under the Chapter 18 subdirectory. Hosting Remote Objects Using IIS Hosting a remote assembly under IIS is even simpler than building aWindows service, as IIS is preprogrammed to allow incoming HTTP requests via port 80. Now, given the fact that IIS is a web server, it should stand to reason that IIS is only able to host remote objects using the HttpChannel type (unlike aWindows service, which can also leverage the TcpChannel type). Assuming this is not perceived as a limitation, follow these steps to leverage the remoting support of IIS:
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.