1. Home
  2. Computing & Technology
  3. Delphi Programming

Implementing a lasso drawing technique

By Zarko Gajic, About.com

Here's one approach to drawing a lasso rectangle using Delphi:

~~~~~~~~~~~~~~~~~~~~~~~~~
1. In the OnMouseDown event for the form
that you are 'lasso-ing' controls on:

bMarquee := True;
ptOrigin := Point(X,Y) ;
ptMove := Point(X,Y) ;

Pen.Color := clBlack;
Pen.Width := 1;
Pen.Style := psDash;
Brush.Style := bsClear;

DrawMarquee(ptOrigin, ptMove, pmNotXor ) ;

2. In the OnMouseMove event for the form...

if bMarquee = True then begin
  DrawMarquee(ptOrigin, ptMove, pmNotXor) ;
  DrawMarquee(ptOrigin, Point(X,Y), pmNotXor) ;
  ptMove := Point(X, Y) ;
  Canvas.Pen.Mode := pmCopy;
end;

3. In the OnMouseUp event for the form...

if bMarquee = True then begin
  bMarquee := False;
  DrawMarquee(ptOrigin, Point(X,Y), pmNotXor) ;
  ptMove := Point(X,Y) ;
end;

4. The DrawMarquee procedure...

procedure myForm.DrawMarquee
   (mStart, mStop : TPoint; AMode : TPenMode) ;
begin
  Canvas.Pen.Mode := AMode;
  Canvas.Rectangle(mStart.X,mStart.Y,mStop.X,mStop.Y) ;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Cursor Pos in TRichEdit
« Get EXE Version Information

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2001 Delphi Tips
  7. Implementing a lasso drawing technique

©2009 About.com, a part of The New York Times Company.

All rights reserved.