tailieunhanh - Pop-Up Menus

Pop-Up Menus Nhiều ứng dụng Windows sử dụng các pop-up menu xuất hiện khi bạn kích chuột phải vào một hình thức hoặc kiểm soát. Các trình đơn thường được ngữ cảnh và lệnh hiển thị được áp dụng duy nhất để kiểm soát hoặc hình thức mà hiện đang có sự tập trung. | Pop-Up Menus Many Windows applications make use of pop-up menus that appear when you right-click a form or control. These menus are usually context-sensitive and display commands that are applicable only to the control or form that currently has the focus. They are sometimes referred to as context menus. Creating Pop-Up Menus In the following exercises you will create two pop-up menus. The first pop-up menu is attached to the firstName and lastName text box controls and allows the user to clear these controls. The second pop-up menu is attached to the form and contains commands for saving the currently displayed member s information and for clearing the form. To do this you will make a copy of an existing menu item as well as create a new one. Create the firstName and lastName pop-up menus 1. In the Design View window displaying MemberForm drag a ContextMenuStrip control from the Menus Toolbars category in the Toolbox and drop it on the form. A ContextMenuStrip object called contextMenuStripl appears at the bottom of the form and another menu strip appears at the top of the form. Note that this is only a temporary location for this new menu strip it is just placed there by Visual Studio 2005 to allow you to edit it and add menu items. At runtime its location will actually be determined by the position of the mouse when the user clicks the right mouse button. 2. Select the contextMenuStripl control type textBoxMenu in the Name text box in the Properties window and then press Enter. 3. Click the Type Here caption that appears under the ContextMenuStrip menu strip at the top of the form not the control . Type Clear Text and then press Enter TIP If the ContextMenuStrip menu strip has disappeared from the form click the textBoxMenu control underneath the form to display it again. 4. Click the firstName text box control next to the First Name label . In the Properties window change the ContextMenuStrip property to textBoxMenu. The ContextMenu property determines which .