Archive for the 'A1' Category

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

Tuesday, June 10th, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.630 STEM.WINDOWS.FORMS Go ahead and take your updated application out for another test drive and try entering in the names of various colors. Once you do, you should see your Form s background color change. If you are interested in checking out some valid color names, look up the System.Drawing.Color type using the Visual Studio 2005 Object Browser or the .NET Framework 2.0 SDK documentation. Creating a Context Menu Let s now examine the process of building a context-sensitive pop-up (i.e., right-click) menu. Under .NET 1.1, the ContextMenu type was the class of choice for building context menus, but under .NET 2.0 the preferred type is ContextMenuStrip. Like the MenuStrip type, ContextMenuStrip maintains a ToolStripItemCollection to represent the possible subitems (such as ToolStripMenuItem, ToolStripComboBox, ToolStripSeperator, ToolStripTextBox, etc.). Drag a new ContextMenuStrip control from the Toolbox onto the Forms designer and rename the control to fontSizeContextStrip using the Properties window. Notice that you are able to populate the subitems graphically in much the same way you would edit the Form s main MenuStrip (a welcome change from the method used in Visual Studio .NET 2003). For this example, add three ToolStripMenuItems named Huge, Normal, and Tiny (see Figure 19-14). This context menu will be used to allow the user to select the size to render a message within the Form s client area. To facilitate this endeavor, create an enum type named TextFontSize within the MenuStripApp namespace and declare a new member variable of this type within your Form type (set to TextFontSize.FontSizeNormal): namespace MainForm { // Helper enum for font size. enum TextFontSize { FontSizeHuge = 30, FontSizeNormal = 20, FontSizeTiny = 8 } public class MainForm : Form { Figure 19-14. Designing a ContextMenuStrip
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

CHAPTER 19 BUILDING A BETTER WINDOW WITH (Best web site)

Monday, June 9th, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.WINDOWS.FORMS 629 At this point, you should be able to compile and run your program. Verify that you can terminate the application via File .Exit as well as pressing Alt+f and then x on the keyboard. Adding a TextBox to the MenuStrip Now, let s create a new topmost menu item named Change Background Color. The subitem in this case will not be a menu item, but a ToolStripTextBox (see Figure 19-13). Once you have added the new control, rename this control to toolStripTextBoxColor using the Properties window. The goal here is to allow the user to enter the name of a color (red, green, pink, etc.) that will be used to set the BackColor property of the Form. First, handle the LostFocus event on the new ToolStripTextBox member variable within the Form s constructor (as you would guess, this event fires when the TextBox within the ToolStrip is no longer the active UI element): public MainWindow() { … toolStripTextBoxColor.LostFocus += new EventHandler(toolStripTextBoxColor_LostFocus); } Within the generated event handler, you will extract the string data entered within the ToolStripTextBox (via the Text property) and make use of the System.Drawing.Color.FromName() method. This static method will return a Color type based on a known string value. To account for the possibility that the user enters an unknown color (or types bogus data), you will make use of some simple try/catch logic: void toolStripTextBoxColor_LostFocus(object sender, EventArgs e) { try { BackColor = Color.FromName(toolStripTextBoxColor.Text); } catch { } // Just do nothing if the user provides bad data. } Figure 19-13. Adding TextBoxes to a MenuStrip
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

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

Sunday, June 8th, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.628 STEM.WINDOWS.FORMS Note As you may know, when the ampersand character (&) is placed before a letter in a menu item, it denotes the item s shortcut key. In this example, you are creating &File . E&xit; therefore, the user may activate the Exit menu by pressing Alt+f, and then x. Each menu item you type into the designer is represented by the ToolStripMenuItem class type. If you open your *.Designer.cs file, you will find two new member variables for each item: partial class MainWindow { … private System.Windows.Forms.MenuStrip mainMenuStrip; private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; } When you use the menu editor, the InitializeComponent() method is updated accordingly. Notice that the MenuStrip s internal ToolStripItemCollection has been updated to contain the new topmost menu item (fileToolStripMenuItem). In a similar fashion, the fileToolStripMenuItem variable has been updated to insert the exitToolStripMenuItem variable into its ToolStripItemCollection collection via the DropDownItems property: private void InitializeComponent() { … // // menuStrip1 // this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem}); … // // fileToolStripMenuItem // this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.exitToolStripMenuItem}); … // // MainWindow // this.Controls.Add(this.menuStrip1); } Last but not least, notice that the MenuStrip control is inserted to the Form s controls collection. This collection will be examined in greater detail in Chapter 21, but for the time being, just know that in order for a control to be visible at runtime, it must be a member of this collection. To finish the initial code of this example, return to the designer and handle the Click event for the Exit menu item using the events button of the Properties window. Within the generated event handler, make a call to Application.Exit: private void exitToolStripMenuItem_Click(object sender, EventArgs e) { Application.Exit(); }
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Web server info - CHAPTER 19 BUILDING A BETTER WINDOW WITH

Saturday, June 7th, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.WINDOWS.FORMS 627 Many Windows Forms controls support such context-sensitive inline editors. As far as MenuStrip is concerned, the editor allows you to quickly do the following: Insert a standard menu system (File, Save, Tools, Help, etc.) using the Insert Standard Items link. Change the docking and gripping behaviors of the MenuStrip. Edit each item in the MenuStrip (this is simply a shortcut to selecting a specific item in the Properties window). For this example, you ll ignore the options of the inline editor and stay focused on the design of the menu system. To begin, select the MenuStrip control on the designer and define a standard File .Exit menu by typing in the names within the Type Here prompts (see Figure 19-12). Figure 19-11. The inline MenuStrip editor Figure 19-12. Designing a menu system
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 A BETTER WINDOW WITH (Web hosting compare)

Friday, June 6th, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.626 STEM.WINDOWS.FORMS Application.Run(new MainWindow()); } } Note The [STAThread] attribute instructs the CLR to host any legacy COM objects (including ActiveX controls) in a single-threaded apartment (STA). If you have a background in COM, you may recall that the STA was used to ensure access to a COM type occurred in a synchronous (hence, thread-safe) manner. Autoreferenced Assemblies Finally, if you examine Solution Explorer, you will notice that aWindows Forms project automatically references a number of assemblies, including System.Windows.Forms.dll and System.Drawing.dll. Again, the details of System.Drawing.dll will be examined in the next chapter. Working with MenuStrips and ContextMenuStrips As of .NET 2.0, the recommended control for building a menu system is MenuStrip. This control allows you to create normal menu items such as File .Exit, and you may also configure it to contain any number of relevant controls within the menu area. Here are some common UI elements that may be contained within a MenuStrip: ToolStripMenuItem: A traditional menu item ToolStripComboBox: An embedded ComboBox ToolStripSeparator: A simple line that separates content ToolStripTextBox: An embedded TextBox Programmatically speaking, the MenuStrip control contains a strongly typed collection named ToolStripItemCollection. Like other collection types, this object supports members such as Add(), AddRange(), Remove(), and the Count property. While this collection is typically populated indirectly using various design-time tools, you are able to manually manipulate this collection if you so choose. To illustrate the process of working with the MenuStrip control, create a new Windows Forms application named MenuStripApp. Using the Forms designer, place a MenuStrip control named mainMenuStrip onto your Form. When you do so, your *.Designer.cs file is updated with a new MenuStrip member variable: private System.Windows.Forms.MenuStrip mainMenuStrip; MenuStrips can be highly customized using the Visual Studio 2005 Forms designer. For example, if you look at the extreme upper-left of the control, you will notice a small arrow icon. After you select this icon, you are presented with a context-sensitive inline editor, as shown in Figure 19-11.
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

CHAPTER 19 BUILDING A BETTER WINDOW WITH (My space web page)

Thursday, June 5th, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.WINDOWS.FORMS 625 Handling Events at Design Time Notice that the Properties window has a button depicting a lightning bolt. Although you are always free to handle Form-level events by authoring the necessary logic by hand (as done in the previous examples), this event button allows you to visually handle an event for a given control. Simply select the control you wish to interact with from the drop-down list box (mounted at the top of the Properties window), locate the event you are interested in handling, and type in the name to be used as an event handler (or simply double-click the event to generate a default name of the form ControlName_ EventName). Assuming you have handled the Click event for the Button control, you will find that the Form1.cs file contains the following event handler: public partial class MainWindow : Form { public MainWindow() { InitializeComponent(); } private void btnButtonTest_Click(object sender, EventArgs e) { } } As well, the Form1.Designer.cs file contains the necessary infrastructure and member variable declaration: partial class MainWindow { … private void InitializeComponent() { … this.btnButtonTest.Click += new System.EventHandler(this.btnButtonTest_Click); } private System.Windows.Forms.Button btnButtonTest; } Note Every control has a default event, which refers to the event that will be handled if you double-click the item on the control using the Forms designer. For example, a Form s default event is Load, and if you double-click anywhere on a Form type, the IDE will automatically write code to handle this event. The Program Class Beyond the Form-centric files, a Visual Studio 2005 Windows application defines a second class that represents the application object (e.g., the type defining the Main() method). Notice that the Main() method has been configured to call Application.EnableVisualStyles() as well as Application.Run(): static class Program { [STAThread] static void Main() { Application.EnableVisualStyles();
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

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

Wednesday, June 4th, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.624 STEM.WINDOWS.FORMS Right-click the Form1.cs icon and select View Code. Here you will see a partial class that contains all of the Form s event handlers, constructors, overrides, and any member you author yourself (note that I renamed this initial class from Form1 to MainWindow using the Rename refactoring): namespace MyVisualStudioWinApp { public partial class MainWindow : Form { public MainWindow() { InitializeComponent(); } } } The default constructor of your Form makes a call to a method named InitializeComponent(), which is defined within the related *.Designer.cs file. This method is maintained on your behalf by Visual Studio 2005, and it contains all of the code representing your design-time modifications. To illustrate, switch back to the Forms designer and locate the Text property in the Properties window. Change this value to something like My Test Window. Now open your Form1.Designer.cs file and notice that InitializeComponent() has been updated accordingly: private void InitializeComponent() { … this.Text = “My Test Window”; } In addition to maintaining InitializeComponent(), the *.Designer.cs file will define the member variables that represent each control placed on the designer. Again, to illustrate, drag a Button control onto the Forms designer. Now, using the Properties window, rename your member variable from button1 to btnTestButton via the Name property. Note It is always a good idea to rename the controls you place on the designer before handling events. If you fail to do so, you will most likely end up with a number of nondescript event handlers, such as button27_Click, given that the default names simply suffix a numerical value to the variable name. Figure 19-10. Each Form is composed of two *.cs files.
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Web server logs - CHAPTER 19 BUILDING A BETTER WINDOW WITH

Tuesday, June 3rd, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.WINDOWS.FORMS 623 Enabling the Deprecated Controls The first bit of good news is that these (deprecated) UI elements are still completely usable under .NET 2.0. The second bit of good news is that if you still wish to program with them, you can add them back to the Toolbox by right-clicking anywhere in the Toolbox and selecting Choose Items. From the resulting dialog box, check off the items of interest (see Figure 19-9). Note At first glance, it might appear that there are redundant listings for a given control (such as the ToolBar). In reality, each listing is unique, as a control may be versioned (1.0 versus 2.0) and/or may be a member of the .NET Compact Framework. Be sure to examine the directory path to select the correct item. At this point, I am sure you are wondering why many of these old standbys have been hidden from view. The reason is that .NET 2.0 provides a set of new menu, toolbar, and status bar centric controls that are now favored. For example, rather than using the legacy MainMenu control to build a menu, you can use the MenuStrip control, which provides a number of new bells and whistles in addition to the functionality found within MainMenu. Note In this chapter, I will favor the use of this new recommend set of UI elements. If you wish to work with the legacy MainMenu, StatusBar, or ToolBar types, consult the .NET Framework 2.0 SDK documentation. Dissecting aVisual Studio 2005 Windows Forms Project Each Form in a Visual Studio 2005 Windows Application project is composed of two related C# files, which can be verified using Solution Explorer (see Figure 19-10). Figure 19-9. Adding additional controls to the Toolbox
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Cpanel web hosting - CHAPTER 19 BUILDING A BETTER WINDOW WITH

Monday, June 2nd, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.622 STEM.WINDOWS.FORMS As you can see, the Toolbox groups UI controls by various categories. While most are selfexplanatory (e.g., Printing contains printing controls, Menus & Toolbars contains recommended menu/toolbar controls, etc.), a few categories deserve special mention: Common Controls: Members in this category are considered the recommended set of common UI controls. All Windows Forms: Here you will find the full set of Windows Forms controls, including various .NET 1.x controls that are considered depreciated. The second bullet point is worth reiterating. If you have worked with Windows Forms using .NET 1.x, be aware that many of your old friends (such as the DataGrid control) have been placed under the All Windows Forms category. Furthermore, the common UI controls you may have used under .NET 1.x (such as MainMenu, ToolBar, and StatusBar) are not shown in the Toolbox by default. Figure 19-7. The Visual Studio 2005 Toolbox Figure 19-8. The Visual Studio 2005 Properties window
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

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

Sunday, June 1st, 2008

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.WINDOWS.FORMS 621 Figure 19-6. The Visual Studio 2005 Windows Application project most of the mundane code on your behalf. Given this, let s say good-bye to the command-line compiler for the time being and turn our attention to the process of building Windows Forms applications using Visual Studio 2005. Source Code The FormLifeTime project can be found under the Chapter 19 subdirectory. Building Windows Applications with Visual Studio 2005 Visual Studio 2005 has a specific project type dedicated to the creation of Windows Forms applications. When you select the Windows Application project type, you not only receive an application object with a proper Main() method, but also are provided with an initial Form-derived type. Better yet, the IDE provides a number of graphical designers that make the process of building a UI child s play. Just to learn the lay of the land, create a new Windows Application project workspace (see Figure 19-6). You are not going to build a working example just yet, so name this project whatever you desire. Once the project has loaded, you will no doubt notice the Forms designer, which allows you to build a UI by dragging controls/components from the Toolbox (see Figure 19-7) and configuring their properties and events using the Properties window (see Figure 19-8).
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.