Web site design - CHAPTER 19 BUILDING A BETTER WINDOW WITH

May 31st, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.620 STEM.WINDOWS.FORMS Figure 19-5. The life and times of a Form-derived type In the Load, Closed, Activated, and Deactivate event handlers, you are going to update the value of a new Form-level System.String member variable (named lifeTimeInfo) with a simple message that displays the name of the event that has just been intercepted. As well, notice that within the Closed event handler, you will display the value of this string within amessage box: private void MainForm_Load(object sender, System.EventArgs e) { lifeTimeInfo += “Load eventn”; } private void MainForm_Activated(object sender, System.EventArgs e) { lifeTimeInfo += “Activate eventn”; } private void MainForm_Deactivate(object sender, System.EventArgs e) { lifeTimeInfo += “Deactivate eventn”; } private void MainForm_Closed(object sender, System.EventArgs e) { lifeTimeInfo += “Closed eventn”; MessageBox.Show(lifeTimeInfo); } Within the Closing event handler, you will prompt the user to ensure she wishes to terminate the application using the incoming CancelEventArgs: private void MainForm_Closing(object sender, CancelEventArgs e) { DialogResult dr = MessageBox.Show(”Do you REALLY want to close this app?”, “Closing event!”, MessageBoxButtons.YesNo); if (dr == DialogResult.No) e.Cancel = true; else e.Cancel = false; } Notice that the MessageBox.Show() method returns a DialogResult type, which has been set to a value representing the button clicked by the end user (Yes or No). Now, compile your code at the command line: csc /target:winexe *.cs Now run your application and shift the Form into and out of focus a few times (to trigger the Activated and Deactivate events). Once you shut down the Form, you will see amessage box that looks something like Figure 19-5. Now, most of the really interesting aspects of the Form type have to do with its ability to create and host menu systems, toolbars, and status bars. While the code to do so is not complex, you will be happy to know that Visual Studio 2005 defines a number of graphical designers that take care of
We recommend high quality webhost to host and run your jsp application: christian web host services.

CHAPTER 19 BUILDING A BETTER WINDOW WITH (Florida web design)

May 31st, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.WINDOWS.FORMS 619 Table 19-10. Select Events of the Form Type Events Meaning in Life Activated Occurs whenever the Form is activated, meaning the Form has been given the current focus on the desktop Closed, Closing Used to determine when the Form is about to close or has closed Deactivate Occurs whenever the Form is deactivated, meaning the Form has lost current focus on the desktop Load Occurs after the Form has been allocated into memory, but is not yet visible on the screen MDIChildActive Sent when a child window is activated The Life Cycle of a Form Type If you have programmed user interfaces using GUI toolkits such as Java Swing, Mac OS X Cocoa, or the raw Win32 API, you are aware that window types have a number of events that fire during their lifetime. The same holds true for Windows Forms. As you have seen, the life of a Form begins when the type constructor is called prior to being passed into the Application.Run() method. Once the object has been allocated on the managed heap, the framework fires the Load event. Within a Load event handler, you are free to configure the look and feel of the Form, prepare any contained child controls (such as ListBoxes, TreeViews, and whatnot), or simply allocate resources used during the Form s operation (database connections, proxies to remote objects, and whatnot). Once the Load event has fired, the next event to fire is Activated. This event fires when the Form receives focus as the active window on the desktop. The logical counterpart to the Activated event is (of course) Deactivate, which fires when the Form loses focus as the active window. As you can guess, the Activated and Deactivate events can fire numerous times over the life of a given Form type as the user navigates between active applications. When the user has chosen to close the Form in question, two close-centric events fire: Closing and Closed. The Closing event is fired first and is an ideal place to prompt the end user with the much hated (but useful) Are you sure you wish to close this application? message. This confirmational step is quite helpful to ensure the user has a chance to save any application-centric data before terminating the program. The Closing event works in conjunction with the CancelEventHandler delegate defined in the System.ComponentModel namespace. If you set the CancelEventArgs.Cancel property to true, you prevent the Form from being destroyed and instruct it to return to normal operation. If you set CancelEventArgs.Cancel to false, the Close event fires and the Windows Forms application terminates, which unloads the AppDomain and terminates the process. To solidify the sequence of events that take place during a Form s lifetime, assume you have a new MainWindow.cs file that handles the Load, Activated, Deactivate, Closing, and Close events within the class constructor (be sure to add a using directive for the System.ComponentModel namespace to obtain the definition of CancelEventArgs): public MainForm() { // Handle various lifetime events. Closing += new CancelEventHandler(MainForm_Closing); Load += new EventHandler(MainForm_Load); Closed += new EventHandler(MainForm_Closed); Activated += new EventHandler(MainForm_Activated); Deactivate += new EventHandler(MainForm_Deactivate); }
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

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

May 30th, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.618 STEM.WINDOWS.FORMS The Functionality of the Form Class The Form class is typically (but not necessarily) the direct base class for your custom Form types. In addition to the large set of members inherited from the Control, ScrollableControl, and ContainerControl classes, the Form type adds additional functionality in particular to main windows, MDI child windows, and dialog boxes. Let s start with the core properties in Table 19-8. Table 19-8. Properties of the Form Type Properties Meaning in Life AcceptButton Gets or sets the button on the Form that is clicked when the user presses the Enter key. ActiveMDIChild Used within the context of an MDI application. IsMDIChild IsMDIContainer CancelButton Gets or sets the button control that will be clicked when the user presses the Esc key. ControlBox Gets or sets a value indicating whether the Form has a control box. FormBorderStyle Gets or sets the border style of the Form. Used in conjunction with the FormBorderStyle enumeration. Menu Gets or sets the menu to dock on the Form. MaximizeBox Used to determine if this Form will enable the maximize and minimize MinimizeBox boxes. ShowInTaskbar Determines if this Form will be seen on the Windows taskbar. StartPosition Gets or sets the starting position of the Form at runtime, as specified by the FormStartPosition enumeration. WindowState Configures how the Form is to be displayed on startup. Used in conjunction with the FormWindowState enumeration. In addition to the expected On-prefixed default event handlers, Table 19-9 gives a list of some core methods defined by the Form type. Table 19-9. Key Methods of the Form Type Method Meaning in Life Activate() Activates a given Form and gives it focus. Close() Closes a Form. CenterToScreen() Places the Form in the dead-center of the screen. LayoutMDI() Arranges each child Form (as specified by the LayoutMDI enumeration) within the parent Form. ShowDialog() Displays a Form as amodal dialog box. More on dialog box programming in Chapter 21. Finally, the Form class defines a number of events, many of which fire during the form s lifetime. Table 19-10 hits the highlights.
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

CHAPTER 19 (Web site construction) BUILDING A BETTER WINDOW WITH

May 29th, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.WINDOWS.FORMS 617 MessageBox.Show(”Right click!”); if (e.Button == MouseButtons.Middle) MessageBox.Show(”Middle click!”); } Responding to Keyboard Events Processing keyboard input is almost identical to responding to mouse activity. The KeyUp and KeyDown events work in conjunction with the KeyEventHandler delegate, which can point to any method taking an object as the first parameter and KeyEventArgs as the second: void MyKeyboardHandler(object sender, KeyEventArgs e); KeyEventArgs has the members of interest shown in Table 19-7. Table 19-7. Properties of the KeyEventArgs Type Property Meaning in Life Alt Gets a value indicating whether the Alt key was pressed Control Gets a value indicating whether the Ctrl key was pressed Handled Gets or sets a value indicating whether the event was fully handled in your handler KeyCode Gets the keyboard code for a KeyDown or KeyUp event Modifiers Indicates which modifier keys (Ctrl, Shift, and/or Alt) were pressed Shift Gets a value indicating whether the Shift key was pressed Update your MainForm to handle the KeyUp event. Once you do, display the name of the key that was pressed inside amessage box using the KeyCode property. public class MainForm : Form { public MainForm() { … // Listen for the KeyUp Event. KeyUp += new KeyEventHandler(MainForm_KeyUp); } private void MainForm_KeyUp (object sender, KeyEventArgs e) { MessageBox.Show(e.KeyCode.ToString(), “Key Pressed!”); } } Now compile and run your program. You should be able to determine not only which mouse button was clicked, but also which keyboard key was pressed. That wraps up our look at the core functionality of the Control base class. Next up, let s check out the role of Form. Source Code The ControlBehaviors project is included under the Chapter 19 subdirectory.
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

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

May 28th, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.616 STEM.WINDOWS.FORMS Figure 19-4. Monitoring mouse movement … // Handle the MouseMove event MouseMove += new MouseEventHandler(MainForm_MouseMove); } // MouseMove event handler. public void MainForm_MouseMove(object sender, MouseEventArgs e) { Text = string.Format(”Current Pos: ({0}, {1})”, e.X, e.Y); } } If you now run your program and move the mouse over your Form, you will find the current (x, y) value display on the caption area (see Figure 19-4). Determining Which Mouse Button Was Clicked One thing to be aware of is that the MouseUp (or MouseDown) event is sent whenever any mouse button is clicked. If you wish to determine exactly which button was clicked (such as left, right, or middle), you need to examine the Button property of the MouseEventArgs class. The value of the Button property is constrained by the related MouseButtons enumeration. Assume you have updated your default constructor to handle the MouseUp event as so: public MainWindow() { … // Handle the MouseUp event. MouseUp += new MouseEventHandler(MainForm_MouseUp); } The following MouseUp event handler displays which mouse button was clicked inside a message box: public void MainForm_MouseUp (object sender, MouseEventArgs e) { // Which mouse button was clicked? if(e.Button == MouseButtons.Left) MessageBox.Show(”Left click!”); if(e.Button == MouseButtons.Right)
You want to have a cheap webhost for your apache application, then check apache web hosting services.

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

May 27th, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.WINDOWS.FORMS 615 namespace MyWindowsApp { public class MainWindow : Form { public MainWindow() { // Use inherited properties to set basic UI. Text = “My Fantastic Form”; Height = 300; Width = 500; BackColor = Color.LemonChiffon; Cursor = Cursors.Hand; } } public static class Program { static void Main(string[] args) { Application.Run(new MainWindow()); } } } Compile your application at this point, just to make sure you have not injected any typing errors: csc /target:winexe *.cs Responding to the MouseMove Event Next, you need to handle the MouseMove event. The goal is to display the current (x, y) location within the Form s caption area. All mouse-centric events (MouseMove, MouseUp, etc.) work in conjunction with the MouseEventHandler delegate, which can call any method matching the following signature: void MyMouseHandler(object sender, MouseEventArgs e); The incoming MouseEventArgs structure extends the general EventArgs base class by adding a number of members particular to the processing of mouse activity (see Table 19-6). Table 19-6. Properties of the MouseEventArgs Type Property Meaning in Life Button Gets which mouse button was pressed, as defined by the MouseButtons enumeration Clicks Gets the number of times the mouse button was pressed and released Delta Gets a signed count of the number of detents the mouse wheel has rotated X Gets the x-coordinate of a mouse click Y Gets the y-coordinate of a mouse click Here, then, is the updated MainForm class that handles the MouseMove event as intended: public class MainForm : Form { public MainForm() {
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

CHAPTER 19 BUILDING A BETTER WINDOW WITH (Web hosting e commerce)

May 26th, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.614 STEM.WINDOWS.FORMS public class MainWindow : Form { protected override void OnMouseDown(MouseEventArgs e) { // Add code for MouseDown event. // Call parent implementation when finished. base.OnMouseDown(e); } } While this can be helpful in some circumstances (especially if you are building a custom control that derives from a standard control; see Chapter 21), you will often handle events using the standard C# event syntax (in fact, this is the default behavior of the Visual Studio 2005 designers). When you do so, the framework will call your custom event handler once the parent s implementation has completed: public class MainWindow : Form { public MainWindow() { MouseDown += new MouseEventHandler(MainWindow_MouseDown); } void MainWindow_MouseDown(object sender, MouseEventArgs e) { // Add code for MouseDown event. } } Beyond these OnXXX() methods, here are a few other methods to be aware of: Hide(): Hides the control and sets the Visible property to false Show(): Shows the control and sets the Visible property to true Invalidate(): Forces the control to redraw itself by sending a Paint event To be sure, the Control class does define additional properties, methods, and events beyond the subset you ve just examined. You should, however, now have a solid understanding regarding the overall functionality of this base class. Let s see it in action. Fun with the Control Class To illustrate the usefulness of some members from the Control class, let s build a new Form that is capable of handling the following events: Respond to the MouseMove and MouseDown events. Capture and process keyboard input via the KeyUp event. To begin, create a new class derived from Form. In the default constructor, you ll make use of various inherited properties to establish the initial look and feel. Note you re now using the System. Drawing namespace to gain access to the Color structure (you ll examine this namespace in detail in the next chapter): using System; using System.Windows.Forms; using System.Drawing;
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.

Jetty web server - CHAPTER 19 BUILDING A BETTER WINDOW WITH

May 25th, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.WINDOWS.FORMS 613 Table 19-4. Core Properties of the Control Type Properties Meaning in Life BackColor, ForeColor, These properties define the core UI of the control (colors, BackgroundImage, Font, Cursor font for text, mouse cursor to display when the mouse is over the widget, etc.). Anchor, Dock, AutoSize These properties control how the control should be positioned within the container. Top, Left, Bottom, Right, Bounds, These properties specify the current dimensions of the ClientRectangle, Height, Width control. Enabled, Focused, Visible These properties each return a Boolean that specifies the state of the current control. ModifierKeys This static property checks the current state of the modifier keys (Shift, Ctrl, and Alt) and returns the state in a Keys type. MouseButtons This static property checks the current state of the mouse buttons (left, right, and middle mouse buttons) and returns this state in a MouseButtons type. TabIndex, TabStop These properties are used to configure the tab order of the control. Opacity This property determines the opacity of the control, in fractions (0.0 is completely transparent; 1.0 is completely opaque). Text This property indicates the string data associated with this control. Controls This property allows you to access a strongly typed collection (ControlsCollection) that contains any child controls within the current control. As you would guess, the Control class also defines a number of events that allow you to intercept mouse, keyboard, painting, and drag-and-drop activities (among other things). Table 19-5 lists some (but not all) events of interest, grouped by related functionality. Table 19-5. Events of the Control Type Events Meaning in Life Click, DoubleClick, MouseEnter, Various events that allow you to interact with the mouse MouseLeave, MouseDown, MouseUp, MouseMove, MouseHover, MouseWheel KeyPress, KeyUp, KeyDown Various events that allow you to interact with the keyboard DragDrop, DragEnter, Various events used to monitor drag-and-drop activity DragLeave, DragOver Paint This event allows you to interact with GDI+ (see Chapter 20) Finally, the Control base class also defines a number of methods that allow you to interact with any Control-derived type. As you examine the methods of the Control type, you will notice that a good number of them have an On prefix followed by the name of a specific event (OnMouseMove, OnKeyUp, OnPaint, etc.). Each of these On-prefixed virtual methods is the default event handler for its respective event. If you override any of these virtual members, you gain the ability to perform any necessary pre- or postprocessing of the event before (or after) invoking your parent s default implementation:
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

CHAPTER 19 BUILDING (Web site design and hosting) A BETTER WINDOW WITH

May 24th, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.612 STEM.WINDOWS.FORMS Although the complete derivation of a Form type involves numerous base classes and interfaces, do understand that you are not required to learn the role of each and every member from each and every parent class or implemented interface to be a proficient Windows Forms developer. In fact, the majority of the members (properties and events in particular) you will use on a daily basis are easily set using the Visual Studio 2005 IDE Properties window. Before we move on to examine some specific members inherited from these parent classes, Table 19-3 outlines the basic role of each base class. Table 19-3. Base Classes in the Form Inheritance Chain Parent Class Meaning in Life System.Object Like any class in .NET, a Form is-a object. System.MarshalByRefObject Recall during our examination of .NET remoting (see Chapter 18) that types deriving from this class are accessed remotely via a reference (not a copy) of the remote type. System.ComponentModel.Component This class provides a default implementation of the IComponent interface. In the .NET universe, a component is a type that supports design-time editing, but is not necessarily visible at runtime. System.Windows.Forms.Control This class defines common UI members for all Windows Forms UI controls, including the Form type itself. System.Windows.Forms.ScrollableControl This class defines support for auto-scrolling behaviors. System.Windows.Forms.ContainerControl This class provides focus-management functionality for controls that can function as a container for other controls. System.Windows.Forms.Form This class represents any custom Form, MDI child, or dialog box. As you might guess, detailing each and every member of each class in the Form s inheritance chain would require a large book in itself. However, it is important to understand the behavior supplied by the Control and Form types. I ll assume that you will spend time examining the full details behind each class at your leisure using the .NET Framework 2.0 SDK documentation. The Functionality of the Control Class The System.Windows.Forms.Control class establishes the common behaviors required by any GUI type. The core members of Control allow you to configure the size and position of a control, capture keyboard and mouse input, get or set the focus/visibility of a member, and so forth. Table 19-4 defines some (but not all) properties of interest, grouped by related functionality.
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

Web hosting colocation - CHAPTER 19 BUILDING A BETTER WINDOW WITH

May 23rd, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.WINDOWS.FORMS 611 The System.EventHandler Delegate Notice that the ApplicationExit event works in conjunction with the System.EventHandler delegate. This delegate must point to methods that conform to the following signature: delegate void EventHandler(object sender, EventArgs e); System.EventHandler is the most primitive delegate used to handle events within Windows Forms, but many variations do exist for other events. As far as EventHandler is concerned, the first parameter of the assigned method is of type System.Object, which represents the object sending the event. The second EventArgs parameter (or a descendent thereof) contains any relevant information regarding the current event. Note EventArgs is the base class to numerous derived types that contain information for a family of related events. For example, mouse events work with the MouseEventArgs parameter, which contains details such as the (x, y) position of the cursor. Many keyboard events work with the KeyEventArgs type, which contains details regarding the current keypress, and so forth. In any case, if you now recompile and run the application, you will find your message box appear upon the termination of the application. Source Code The AppClassExample project can be found under the Chapter 19 subdirectory. The Anatomy of a Form Now that you understand the role of the Application type, the next task is to examine the functionality of the Form class itself. Not surprisingly, the Form class inherits a great deal of functionality from its parent classes. Figure 19-3 shows the inheritance chain (including the set of implemented interfaces) of a Form-derived type using the Visual Studio 2005 Object Browser. Figure 19-3. The derivation of the Form type
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.