Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Tài liệu Adding Menus and Processing Menu Events ppt
Nội dung xem thử
Mô tả chi tiết
Adding Menus and Processing Menu Events
Microsoft Visual Studio 2005 lets you add menus and menu items to a form in two ways.
You can use the Visual Studio 2005 integrated development environment (IDE) and the
menu editor to create a menu graphically. You can also write code that creates a
MenuStrip object (MenuStrip is a class defined in the Windows Forms library), and then
add ToolStripMenuItem objects to it (ToolStripMenuItem is another class in the
Windows Forms library).
Laying out a menu is only half of the story. When a user clicks a command on a menu,
the user expects something to happen! You activate the commands by trapping menu
events and executing code in much the same way as you do for handling control events.
Creating a Menu
In the following exercise, you will use the graphical approach to create menus for the
Middleshire Bell Ringers Association application. We will cover how to manipulate and
create menus programmatically later in this chapter.
Create the File menu
1. Start Visual Studio 2005.
2. Open the BellRingers project, located in the \Microsoft Press\Visual CSharp Step
by Step\Chapter 21\BellRingers folder in your My Documents folder. This is the
Middleshire Bell Ringers application. It should be the same as the version that you
completed in Chapter 20.
3. Display MemberForm in the Design View window. (Click MemberForm.cs in the
Solution Explorer, and then click Designer on the View menu, or double-click
MemberForm.cs in the Solution Explorer).
MemberForm appears.
4. In the Toolbox, expand the Menus & Toolbars category. Drag a MenuStrip control
anywhere onto MemberForm.
IMPORTANT
Be sure to drop the MenuStrip control onto the form, and not onto a control on the
form. Some controls, such as GroupBox, can have their own menus, and dropping
a menu on such a control will create a menu for that control only.