 TStretchHandle V2.0

Author: Anthony Scott 
CIS 75567,3547, Internet 75567.3547@compuserve.com

The TStretchHandle component for Delphi has been significantly improved over its early incarnation as an experimental first component.  Version 2.0 has better support for manipulating multiple child components, features more consistent visual behaviour, and has been tested with both Windows(tm) 3.1 and Windows(tm) 95.  Freeware, feel free to distribute but please don't sell it.

Overview:

TStretchHandle imitates those grabhandles you see when you manipulate components in Delphi's Forms Designer.  It encapsulates drag/drop and resize functionality using the left mouse button and arrow keys.  Simply drop an instance of TStretchHandle on your form, and attach the component(s) you want to manipulate at runtime by calling the Attach method.  A typical way to do this would be to invoke Attach in the target control's OnMouseDown event handler:

procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  StretchHandle1.Attach(Label1);
end;

Grab handles will appear on the corner and sides of the target (child) control, and TStretchHandle does the rest.  Despite the nomenclature, TStretchHandle does not become the Parent of the control(s) it manages; in fact, it will automatically adopt the Parent of the first 'child'.  It will insist that all its children be siblings; when a control on a different Parent is attached, an implicit Detach will occur first.  An individual child control can be released with a call to the ReleaseChild method, or Detach can be called to release all children at once.  Properties are provided to control the color of the grab handle boxes, the cursor to use when dragging, and the granularity of the optional snap-to grid.

Notes:

* Unlike its predecessor, TStretchHandle V2.0 manages child controls via an internal array; the Child property has therefore been replaced by the runtime-only Children[] array property.  Children[], ChildCount and Attached are readonly properties.
 
* TStretchHandle does not employ "real" drag/drop when dragging components - they are simply moved to a new position on the same Parent.

Installation:

The file HANDLES.ZIP contains:

README.DOC		- this file (also in .TXT format)
HANDLES.DCR		- the component palette icon for this component
HANDLES.PAS		- the source for TStretchHandle
PROJECT1.DPR		- a sample/demo project (3 files)
UNIT1.DFM
UNIT1.PAS

To install, unpack the .ZIP file and run HANDLES.PAS from Delphi's Options|Install Components, as per usual.  It is always wise to back up COMPLIB.DCL before you install a new component.  Make sure HANDLES.PAS and HANDLES.DCR are in the same directory.

A sample project is included; simply load and run PROJECT1.DPR from the Delphi IDE.  

Properties:		Methods:						Events:

Attached		Create(AOwner: TComponent)				OnClick
ChildCount		Destroy							OnDblClick
Children[]		Attach(ChildControl: TControl)				OnMouseDown
Color			Detach							OnMouseMove
Cursor			ReleaseChild(ChildControl: TControl)			OnMouseUp
DragCursor		IndexOf(ChildControl: TControl)				OnKeyDown
Enabled			BringToFront						OnKeyUp
GridX			SendToBack						OnKeyPress
GridY			SetBounds(ALeft, ATop, AWidth, AHeight: Integer)
Height			SetColors(Color1, Color2: TColor)
HelpContext
Hint
Left
Locked			Exceptions:
Name			
ParentShowHint		EBadChild  (when you try to attach a Form - sorry, couldn't resist!)
PopupMenu
SecondaryColor
ShowHint
SnapToGrid
Tag
Top
Visible
Width

Known problems:

Yes, there are a couple.  Notably, the handles component is sized to the bounding rectangle of all its children, and this has some side effects.  Events in the transparent area (the space between multiple children) are still seen by the TStretchHandle component.  MouseDown and MouseUp events are passed through to underlying controls, but MouseMove and DoubleClick events are not.  This also affects the behaviour of the Hint and PopupMenu properties - hints and menus assigned to TStretchHandle may show up in seemingly vacant areas.

Support:

Any queries, suggestions or thoughts are welcome.   My thanks to those folks who have already offered helpful feedback.

Please write or email:

CIS: 75567,3547

Anthony Scott
2001 S. Halsted
Chicago, IL, 60608


