Click here to Skip to main content
14,767,943 members
Articles » Desktop Development » Miscellaneous » General
Posted 5 Jun 2003


80 bookmarked

Drawing trackers, moving and resizing the objects using double buffering.

Rate me:
Please Sign up or sign in to vote.
3.83/5 (24 votes)
5 Jun 2003
Drawing, Positioning and resizing the Boxes with double buffering

Image 1


In VC++ we have a class CRectTracker which helps drawing the trackers and also there is function a DrawFocusRect() with which tracker behavior can be achieved. In C# I did not find any kind of such functionality (if there is then I am unaware at the moment.). So I decided to make program which draw box with tracker and allows manipulation with the box with the help of trackers.

Key features

  • Drawing trackers
  • Moving the boxes having trackers attached to it.
  • Resizing the box with the help of trackers.
  • Selection is made in Z Order.

I tried to avoid Form’s Invalidate() function as it generates flickering effects and drawing is not smooth. I designed the program in a way to maximize the usage of double buffering to avoid flickering effect.

Using the code

Class CRectTracker

DrawSelectionGhostRect()Draws the given ghost rectangle on the specified bitmap
InitTrackerRects()Initializes the eight rectangle of the tracker.
DrawSelectionTrackers()Draws the already initialized tracker rectangles
CursorCheck()Checks the position of the cursor and changes the form cursor with appropriate cursor and returns the border of the rectangle for the resizing purpose.

In the main program there are three modes of the program. First is the “None mode” which indicates that user is not drawing, second mode is the “Drawing mode” and it is invoked when user selects the Box icon from the toolbar and third is the “selection mode” it is invoked when user selects a box for changing the positioning or size.  

There is main bitmap which holds the current drawing. Whenever a change is required like drawing rubber band selection or drawing tracker a copy of the main bitmap is made and saved in TrackerImage bitmap and all the changes are made in it and in the end it is assigned to the main bitmap. Even when repaint is required then RePaintForm() function is called instead of calling paint() function of the form to avoid the flickering effect.


A simple program that demonstrates double buffering & tracker drawing is included. OnPaint() generates flickering effects so it is recommended to draw first on the bitmap and then on the form.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Sweden Sweden
No Biography provided

Comments and Discussions

Generalit's really great! Pin
Southmountain24-Aug-19 13:29
MemberSouthmountain24-Aug-19 13:29 
QuestionI can't open the demo code. Better code idea? Pin
Member 33908644-Jul-09 7:18
MemberMember 33908644-Jul-09 7:18 
I can't open the demo code. I have VB net installed. Is it possible to convert code to vb net? . Does anyone know about geometric picking objects using distance criterion method? I'd like to develope a simple public GDI lib that you can select and edit a simple objects like line, polyline, ellipse... by clicking mouse. I know for old DOS system, this was discovered and developed very well decades ago. I don't know GDI lib for .net has those functions built-in or it was ignored and leave the burden to developer to figure it out. If that the case then I have to start to work on it from base zero. Any idea would be appreciate.Cool | :cool:
GeneralMy vote of 1 Pin
Mrtnk25-Jun-09 1:26
MemberMrtnk25-Jun-09 1:26 
GeneralRe: My vote of 1 Pin
Ed Gadziemski8-Mar-14 12:08
professionalEd Gadziemski8-Mar-14 12:08 
Generaldraw a rectangle on image Pin
Babita Shivade29-Apr-09 2:14
MemberBabita Shivade29-Apr-09 2:14 
Questionhow to add a tracker for a bit map Pin
sandun neelanga31-Oct-07 0:09
Membersandun neelanga31-Oct-07 0:09 
AnswerRe: how to add a tracker for a bit map Pin
00thilani2-Jan-08 7:41
Member00thilani2-Jan-08 7:41 
Generalsource code Pin
Raja Sekhar Bandaru25-Apr-07 15:31
MemberRaja Sekhar Bandaru25-Apr-07 15:31 
GeneralRe: source code Pin
khurram7t825-Apr-07 22:27
Memberkhurram7t825-Apr-07 22:27 
Questionhow to delete a selected object? Pin
yuxuant31-Oct-05 20:28
Memberyuxuant31-Oct-05 20:28 
AnswerRe: how to delete a selected object? Pin
khurram7t85-Nov-05 7:31
Memberkhurram7t85-Nov-05 7:31 
Generalthanks! I have a question Pin
xuxiaodong7-Jun-04 4:24
Memberxuxiaodong7-Jun-04 4:24 
GeneralRe: thanks! I have a question Pin
khurram7t88-Jun-04 19:49
Memberkhurram7t88-Jun-04 19:49 
GeneralExcellent Pin
Chieu Luu21-Nov-03 10:06
MemberChieu Luu21-Nov-03 10:06 
GeneralRe: Excellent Pin
Nickle18-Jan-04 11:19
MemberNickle18-Jan-04 11:19 
GeneralThanks Pin
Xboss30-Sep-03 21:22
MemberXboss30-Sep-03 21:22 
GeneralDrawing a Tracker Pin
JacksonBrown196012-Sep-03 6:23
MemberJacksonBrown196012-Sep-03 6:23 
Generalthanks Pin
birol.bellikan@kibarholding.com27-Jun-03 2:22
Memberbirol.bellikan@kibarholding.com27-Jun-03 2:22 
GeneralThanks! Pin
wgaiw11-Jun-03 4:31
Memberwgaiw11-Jun-03 4:31 
Generalmultiple selection & group move Pin
Dan Colasanti6-Jun-03 9:05
professionalDan Colasanti6-Jun-03 9:05 
Generalcorner resizers & Z-order selection problems Pin
Dan Colasanti6-Jun-03 8:58
professionalDan Colasanti6-Jun-03 8:58 
GeneralRe: corner resizers & Z-order selection problems Pin
Member 3683936-Jun-03 17:48
MemberMember 3683936-Jun-03 17:48 
GeneralRe: corner resizers & Z-order selection problems Pin
Nickle18-Jan-04 11:18
MemberNickle18-Jan-04 11:18 
QuestionAny chance doing this in C++? Pin
WREY6-Jun-03 3:28
MemberWREY6-Jun-03 3:28 
AnswerRe: Any chance doing this in C++? Pin
NormDroid6-Jun-03 6:18
professionalNormDroid6-Jun-03 6:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.