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

Drag-and-drop is often a convenient way for users to manipulate objects, You can let users drag an entire control, or let them drag items from one control such as a list box or tree view into another.

  1. Ending a drag operation

A drag operation ends when the item is either successfully dropped or released over a control that cannot accept it. At this point an end-drag event is sent to the con­trol from which the drag was initiated. To enable a control to respond when items have been dragged from it, attach an event handler to the control's OnEndDrag event.

  1. Implementing drag and dock in controls

Descendants of TWinControl can act as docking sites and descendants of TControl can act as child windows that are docked into docking sites. For example, to provide a docking site at the left edge of a form window, align a panel to the left edge of the form and make the panel a docking site. When dockable controls are dragged to the panel and released, they become child controls of the panel.

  1. Controlling how child controls are docked

A docking site automatically accepts child controls when they are released over the docking site. For most controls, the first child is docked to fill the client area, the second splits that into separate regions, and so on. Page controls dock children into new tab sheets (or merge in the tab sheets if the child is another page control).

  1. Controlling how child controls are undocked

A docking site automatically allows child controls to be undocked when they are dragged and have a DragMode property of dmAutomatic. Docking sites can re­spond when child controls are dragged off, and even prevent the undocking, in an OnUnDock event handler: property OnUnDock: TunDockEvent.

  1. Controlling how child controls respond to drag-and-dock operations

Dockable child controls have two events that occur during drag-and-dock op­erations: OnStartDock, analogous to the OnStartDrag event of a drag-and drop operation. allows the dockable child control to create a custom drag object. OnEndDock, like OnEndDrag, occurs when the dragging terminates.

5.7 Setting text alignment

In a rich edit or memo component, text can be left- or right-aligned or centered. To change text alignment, set the edit component's Alignment property. Alignment takes effect only if the WordWrap property is True; if word wrapping is turned off, there is no margin to align to.

    1. Adding scroll bars at runtime

Rich edit and memo components can contain horizontal or vertical scroll bars, or both, as needed. When word wrapping is enabled, the component needs only a ver­tical scroll bar. If the user turns off word wrapping, the component might also need a horizontal scroll bar, since text is not limited by the right side of the editor.

To add scroll bars at runtime:

    1. Determine whether the text might exceed the right margin. In most cases, this means checking whether word wrapping is enabled. You might also check whether any text lines actually exceed the width of the control.

    2. Set the rich edit or memo component's ScrollBars property to include or ex­clude scroll bars.

    1. Adding the clipboard object

Most text-handling applications provide users with a way to move selected text between documents, including documents in different applications. TCIipboard object encapsulates a clipboard (such as the Windows Clipboard) and includes methods for cutting, copying, and pasting text (and other formats, including graphics). The Clip­board object is declared in the Clipbrd unit.

    1. Selecting text

For text in an edit control, before you can send any text to the clipboard, that text must be selected. Highlighting of selected text is built into the edit components. When the user selects text, it appears highlighted.

5.11 Selecting all text

The Select All method selects the entire contents of an edit control, such as a rich edit or memo component. This is especially useful when the component's con­tents exceed the visible area of the component. In most other cases, users select text with either keystrokes or mouse dragging.

    1. Cutting, copying, and pasting text

Applications that use the Clipbrd unit can cut, copy, and paste text, graphics, and objects through the clipboard. The edit components that encapsulate the standard text-handling controls all have methods built into them for interacting with the clip­board.

To cut, copy, or paste text with the clipboard, call the edit component's CutTo- Clipboard, CopyToClipboard, and PasteFromClipboard methods, respectively.