CHAPTER 19 BUILDING A BETTER WINDOW WITH (Web design company)
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.