Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Анг-язык на 8.10.12.docx
Скачиваний:
2
Добавлен:
17.11.2019
Размер:
27.53 Кб
Скачать
    1. Disabling menu items

It is often useful to disable menu commands without removing them from the menu. For example, in a text editor, if there is no text currently selected, the Cut, Copy, and Delete commands are inapplicable. An appropriate time to enable or disable menu items is when the user selects the menu. To disable a menu item, set its Enabled property to False.

5.14 Providing a pop-up menu

Pop-up, or local, menus are a common ease-of-use feature for any application. They enable users to minimize mouse movement by clicking the right mouse button in the application workspace to access a list of frequently used commands.

In a text editor application, for example, you can add a pop-up menu that re­peats the Cut, Copy, and Paste editing commands. These pop-up menu items can use the same event handlers as the corresponding items on the Edit menu. You don't need to create accelerator or shortcut keys for pop-up menus because the corresponding regular menu items generally already have shortcuts.

To add a pop-up menu to a form:

    1. Place a pop-up menu component on the form.

    2. Use the Menu Designer to define the items for the pop-up menu.

    3. Set the PopupMenu property of the form or control that displays the menu to the name of the pop-up menu component.

    4. Attach handlers to the OnClick events of the pop-up menu items.

5.15 Handling the On Popup event

You may want to adjust pop-up menu items before displaying the menu, just as you may want to enable or disable items on a regular menu. With a regular menu, you can handle the OnClick event for the item at the top of the menu.

With a pop-up menu, however, there is no top-level menu bar, so to prepare the pop-up menu commands, you handle the event in the menu component itself. The pop-up menu component provides an event just for this purpose, called OnPopup.

To adjust menu items on a pop-up menu before displaying them:

    1. Select the pop-up menu component.

    2. Attach an event handler to its OnPopup event.

    3. Write code in the event handler to enable, disable, hide, or show menu items.

    1. Adding graphics to controls

Several controls let you customize the way the control is rendered. These in­clude list boxes, combo boxes, menus, headers, tab controls, list views, status bars, tree views, and toolbars. Instead of using the standard method of drawing a control or its items, the control's owner (generally, the form) draws them at runtime. The most common use for owner-draw controls is to provide graphics instead of, or in addition to, text for items.

    1. Indicating that a control is owner-drawn

To customize the drawing of a control, you must supply event handlers that render the control's image when it needs to be painted. Some controls receive these events automatically. For example, list views, tree views, and toolbars all receive events at various stages in the drawing process without your having to set any proper­ties. These events have names such as OnCustomDraw or OnAdvancedCustomDraw.

Other controls, however, require you to set a property before they receive owner-draw events. List boxes, combo boxes, header controls, and status bars have a property called Style. Style determines whether the control uses the default drawing (called the "standard" style) or owner drawing. Grids use a property called Default-

Drawing to enable or disable the default drawing. List views and tab controls have a property called OwnerDraw that enables or disabled the default drawing.

List boxes and combo boxes have additional owner-draw styles, called fixed and variable. Other controls are always fixed, although the size of the item that con­tains the text may vary, the size of each item is determined before drawing the con­trol.