
- •Implementing drag and drop in controls
- •Ending a drag operation
- •Implementing drag and dock in controls
- •Disabling menu items
- •5.14 Providing a pop-up menu
- •5.15 Handling the On Popup event
- •Adding graphics to controls
- •Indicating that a control is owner-drawn
- •Adding images to an application
- •Adding images to a string list
- •Drawing owner-drawn items
- •Sizing owner-draw items
- •5.22. Drawing owner-draw items
Adding images to an application
An image control is a nonvisual control that contains a graphical image, such as a bitmap. You use image controls to display graphical images on a form. You can also use them to hold hidden images that you'll use in your application. For example, you can store bitmaps for owner-draw controls in hidden image controls, like this:
Add image controls to the main form.
Set their Name properties.
Set the Visible property for each image control to False.
Set the Picture property of each image to the desired bitmap using the Picture editor from the Object Inspector.
The image controls are invisible when you run the application. The image is stored with the form so it doesn't have to be loaded from a file at runtime.
Adding images to a string list
Once you have graphical images in an application, you can associate them with the strings in a string list. You can either add the objects at the same time as the strings, or associate objects with existing strings. The preferred method is to add objects and strings at the same time, if all the needed data is available.
Drawing owner-drawn items
When you indicate that a control is owner-drawn, either by setting a property or supplying a custom draw event handler, the control is no longer drawn on the screen. Instead, the operating system generates events for each visible item in the control. Your application handles the events to draw the items.
Sizing owner-draw items
Before giving your application the chance to draw each item in a variable owner-draw control, the control receives a measure-item event, which is of type TMeasureltemEvent. TMeasureltemEvent tells the application where the item appears on the control.
Delphi determines the size of the item (generally, it is just large enough to display the item's text in the current font). Your application can handle the event and change the rectangle chosen. For example, if you plan to substitute a bitmap for the item's text, change the rectangle to the size of the bitmap. If you want a bitmap and text, adjust the rectangle tb be large enough for both.
To change the size of an owner-draw item, attach an event handler to the measure-item event in the owner-draw control. Depending on the control, the name of the event can vary. List boxes and combo boxes use OnMeasureltem. Grids have no measure-item event.
The sizing event has two important parameters: the index number of the item and the height of that item. The height is variable: the application can make it either smaller or larger. The positions of subsequent items depend on the size of preceding items.
5.22. Drawing owner-draw items
When an application needs to draw or redraw an owner-draw control, the operating system generates draw-item events for each visible item in the control. Depending on the control, the item may also receive draw events for the item as a part of the item.
To draw each item in an owner-draw control, attach an event handler to the draw-item event for that control.
Задания
1. Answer the questions:
What is drag-and drop?
When does a drag operation end?
How can descendants ofTWinControl can act?
What events do occur during drag-and dock operations?
How can you change text alignment?
Name steps for adding scroll bars at runtime.
What does TClipboard object encapsulate and include?.
What actions do you need to cut, copy, or paste text?
How can you add a pop-up menu to a form? j) Tell about adjusting menu items.
Tell about customizing the drawing of a control. I) What can you say about sizing owner-draw items?
2. переместить элемент из одного средства управления в другое; удачно опущен; в этой точке; событие конца перемещения; прикрепить (установить) драйвер события; прикрепляющая сторона; выравнивать панель; разбивать на несколько групп; предотвращать расстыковку; переход на новую строку выключен; горизонтальные и вертикальные полосы прокрутки; превышать поле; вставить текст; формировать буфер обмена; включать методы; отключить команды меню; неподходящие команды; добавить всплывающее меню; уменьшить движение мышки; быстрые клавиши; короткий путь; корректировать элементы всплывающего меню; сохранить точечные рисунки; графическое изображение; изменить прямоугольник; высота элемента; последующие элементы зависят от размера предыдущих элементов.
3. Read the definitions of the following words and word combinations in the technical English and compare with their meanings in the basic English.
Owner - an object responsible for freeing the resources used by other (owned) objects.
Drag-and-dock - the process by which a user can drag a control and dock it to another, parent control. In drag-and-dock operations, the docked controls are hosted by a parent windowed control; but can function independently. Controls that can be dragged and docked can also remain undocked as floating windows. This is in contrast to the controls that are dragged as part of a drag-and-drop operation, which do not function independently of the parent control.
Drag-and-drop - the process by which a user can drag a control or part of a control to another location or another parent control Drag-and-drop operations are typically used for moving the items in a list or tree view.
Unlike the controls moved by a drag-and-dock operation, the dragged item or control in a drag-and-drop operation can't function independently of its parent control. If the target of a drag-and-drop operation does not accept the dragged object, the operation fails and the dragged object returns to its starting point.
Dock site - a windowed control that can act as the target of a drag-and-dock operation.
Descendant - a class derived from another class. A descendant is type compatible with all of its ancestors.