For everything to be correct, you should probably write a descendant class. Override the method Paintto draw the dimension pen, and override the methods MouseDown, MouseUpand MouseMoveto add resizing functionality to the control.
I think a better solution than trying to draw TPanelin the application code for several reasons:
- The property
Canvasis protected in TPanel, so you do not have access to it from outside the class. You can get around this with a type, but it's a hoax. - Variability sounds more like a panel function than an application function, so put it in the code for the control panel, and not in the main application code.
Here you can start:
type
TSizablePanel = class(TPanel)
private
FDragOrigin: TPoint;
FSizeRect: TRect;
protected
procedure Paint; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
end;
procedure TSizeablePanel.Paint;
begin
inherited;
// Draw a sizing grip on the Canvas property
// There a size-grip glyph in the Marlett font,
// so try the Canvas.TextOut method in combination
// with the Canvas.Font property.
end;
procedure TSizeablePanel.MouseDown;
begin
if (Button = mbLeft) and (Shift = [])
and PtInRect(FSizeRect, Point(X, Y)) then begin
FDragOrigin := Point(X, Y);
// Need to capture mouse events even if the mouse
// leaves the control. See also: ReleaseCapture.
SetCapture(Handle);
end else inherited;
end;
source
share