Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Drawing a Marquee or XON/XOFF Rectangle to select objects at runtime

53 views
Skip to first unread message

rkr...@pacbell.net

unread,
Jan 15, 1997, 3:00:00 AM1/15/97
to

Does anyone know how to draw a box on the canvas when the user clicks
the left mouse button and drags to a new location.

I want to select multiple objects on the canvas at runtime ..

Like CorelDraw for instance ...


Thanks!


Rkr

Nigel Stratton

unread,
Jan 17, 1997, 3:00:00 AM1/17/97
to

Take a look at the Delphi SuperPage Web Site, worth searching for 'Rubber
Banding' techniques.
I think I saw an example there

Hope this helps
Nigel Stratton
Fairplay

rkr...@pacbell.net wrote in article <32DDC2...@pacbell.net>...

Kevin Read

unread,
Jan 17, 1997, 3:00:00 AM1/17/97
to

We don't know why but rkr...@pacbell.net wrote:

>Does anyone know how to draw a box on the canvas when the user clicks
>the left mouse button and drags to a new location.
>
>I want to select multiple objects on the canvas at runtime ..

Here's the method I use to Rubber Band on and image control. The same
works for a form.


Declare some private integers to store the XY positions whilst drawing.

private
{ Private declarations }
NoOfPoints, X1,Y1,X2,Y2 : Integer;
Drawing : Boolean;

On the Mouse down event set the drawing mode etc.

procedure TMain.imgPicMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
with imgPic do
begin
Canvas.Pen.Mode := pmXOr;
Canvas.Pen.Style := psDot;
X1 := X; Y1 := Y; X2 := X; Y2 := Y;
end;
end;

procedure TMain.imgPicMouseMove(Sender: TObject; Shift: TShiftState; X, Y:
Integer);
begin
StatusBar.Caption := intToStr(X) + ' : ' + intToStr(Y);
if ssLeft in Shift then
begin
with imgPic do
begin
Drawing := True;
{clear the last line first}
Canvas.PolyLine([Point(X1,Y1),Point(X2,Y1),Point(X2,Y2)]);
Canvas.PolyLine([Point(X1,Y1),Point(X1,Y2),Point(X2,Y2)]);
X2 := X; Y2 := Y;
{now draw the new line}
Canvas.PolyLine([Point(X1,Y1),Point(X2,Y1),Point(X2,Y2)]);
Canvas.PolyLine([Point(X1,Y1),Point(X1,Y2),Point(X2,Y2)]);
end;
end
else
Drawing := False;

end;

procedure TMain.imgPicMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Drawing = True then
Do something with the selected region ......
end;

Regards
Kevin


*************************************
* Kevin Read
* E-Mail: ke...@fbs.com.au
* http://www.fbs.com.au
*************************************

0 new messages