Click here to Skip to main content
11,928,078 members (38,816 online)
Click here to Skip to main content
Add your own
alternative version


198 bookmarked

Drawing Library

, 10 Dec 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
A library for creating shapes and developing tools.

Screenshot - Painter.JPG


This is a generic library for drawing (work in progress). It is composed of some base tools and shapes. It allows you to draw shapes that you want to create, and develop tools to manage your figures.

Using the code

This piece of code describes the implementation of a derived class from Shape and a a derived class from Tool.

public class Ellipse : Shape
    public Ellipse()
        Geometric.AddEllipse(new System.Drawing.Rectangle(0, 0, 1, 1));

    public Ellipse(Ellipse ellipse) : base(ellipse)

    public override object Clone()
        return new Ellipse(this);
// ....

public class Select : Tool    

    // Override IActions Interface functions

    public override void MouseDown(IDocument document, MouseEventArgs e)
        base.MouseDown(document, e);

        if (SelectShape(document.Shapes, e.Location) == HitPositions.None)

        if (SelectedShapes != null)
            SelectedShapes(this, Select.GetSelectedShapes(document.Shapes));

    public override void MouseUp(IDocument document, MouseEventArgs e)
        base.MouseUp(document, e);

        document.ActiveCursor = Cursors.Default;

It is very important to implement the copy constructor and the function Clone for every new shape, while it is convenient to override the IActions interface during the implementation of a new tool.

Main schemes

In the documentation, there are these schemes:

  • Orange color describes a hot spot class (interface or abstract class usually).
  • Yellow color describes active classes.
  • Blue color describes passive classes (data containers or structs usually).
  • Light grey color describes classes of the framework but not important in the current scheme.
  • Dark grey color describes classes external to the framework.

This scheme represents the actual shapes hierarchy:

Shapes hierarchy

This scheme represents the actual tools hierarchy:

Tools hierarchy

This scheme represents the communication channel between the drawing panel, tools, and shapes:

Hooking Tools-Shapes

The IActions interface contains all the panel actions used by the tools; for example, mouse down and mouse move, and also the paint function. IDocument is an interface, but it is blue because it is only a connection point between tools and shapes, and so it is a passive class.

The following scheme represents the relation between transformers and shapes. Transformers are used to handle shapes moving, so if you want to add any new move, you must only derive two classes, Transformer and CompositeTransformer, and not all the classes in the shapes hierarchy.

Hooking Transformers-Shapes

This scheme represents the actual appearances hierarchy:

Appearances hierarchy

Other schemes are available in the documentation.

Points of interest

To rotate a shape, choose the rotate tool and select the shape. Do a mouse click down and move. To rotate relative to a non-center point, select a shape, click the Ctrl key, do mouse click down, and move.

Rotate example

To deform a shape, change the property Marked to true, and choose the deform tool, do a mouse click down on a marker, and move. Try to group shapes and do the same operations above.

Deform example


The serialization operations are made by XmlSerializer. The performance is not very great.


  • Zoom functionality.
  • Grid on panel.
  • DrawFreeLine tool with possibility to decide the minimum offset between two consecutive points.

Grid example and DrawFreeLine tool

See the Layout options for the Bring To Front and Send To Back functionalities.

Last updates

Added possibility to move shapes with arrows and Control key.

Bug fixes

Modified setter methods of the Text shape to maintain the text state after rotation.

Known bugs

  • Deform tool is not precise on shape border markers.
  • A problem with resize tool and grid enabled.
  • The Undo-Redo mechanism is not precise.

Future developments

  • Improvement of tools (for example, resize).
  • Improvement of performance.
  • Development of other tools.


For documentation:

For object-oriented and color theory and other software development information:


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
Italy Italy
I am a biomedical engineer. I work in Genoa as software developer. I developed MFC ActiveX controls for industrial automation for 2 years and packages for Visual Studio 2005 for 1 year. Currently I'm working in .NET 3.5 in biomedical area.

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
Herre Kuijpers14-Dec-12 22:53
memberHerre Kuijpers14-Dec-12 22:53 
QuestionCould You please tell me how you create the class diagram ? Pin
Sia_Mak3-Dec-12 12:39
memberSia_Mak3-Dec-12 12:39 
AnswerRe: Could You please tell me how you create the class diagram ? Pin
jonnynolimits10-Dec-12 3:01
memberjonnynolimits10-Dec-12 3:01 
QuestionMultiSelect Flicker when going from bottom to top Pin
ScottGBlood22-Mar-12 2:14
memberScottGBlood22-Mar-12 2:14 
GeneralMy vote of 5 Pin
manoj kumar choubey26-Feb-12 22:15
membermanoj kumar choubey26-Feb-12 22:15 
QuestionMove with resize Pin
Ahmad Saffarini3-Jul-11 22:40
memberAhmad Saffarini3-Jul-11 22:40 
Generalhi! i want to create object flash for run file swf Pin
thangnx6-May-11 0:58
memberthangnx6-May-11 0:58 
GeneralMy vote of 5 Pin
thichngaodu30-Oct-10 22:14
memberthichngaodu30-Oct-10 22:14 
Generalpublic Line(PointF start, PointF end) Pin
hotthoughtguy9-Apr-10 10:00
memberhotthoughtguy9-Apr-10 10:00 
JokeCool Pin
iccb101314-Mar-10 23:31
membericcb101314-Mar-10 23:31 
QuestionImage resizing Pin
Kevin Platt29-Jul-09 15:18
memberKevin Platt29-Jul-09 15:18 
AnswerRe: Image resizing Pin
jonnynolimits25-Aug-09 3:05
memberjonnynolimits25-Aug-09 3:05 
GeneralZoom bug Pin
Profesjocom9-Mar-09 15:31
memberProfesjocom9-Mar-09 15:31 

I find something like that

when I zoomin my view by wheelmouse scroll twice
and the zoomout by wheelmouse scroll twice
I get different shape dimension then original

can you tell me how to fix that?

Zoom function just change dimension of shape or is that ratio, because when I zoom in my dimensions change.

GeneralRe: Zoom bug Pin
Profesjocom9-Mar-09 16:30
memberProfesjocom9-Mar-09 16:30 
Generalproblem with modify size by textbox Pin
Profesjocom20-Feb-09 12:31
memberProfesjocom20-Feb-09 12:31 
GeneralRe: problem with modify size by textbox Pin
jonnynolimits5-Mar-09 6:42
memberjonnynolimits5-Mar-09 6:42 
GeneralRe: problem with modify size by textbox Pin
Profesjocom7-Mar-09 11:26
memberProfesjocom7-Mar-09 11:26 
GeneralRe: problem with modify size by textbox Pin
jonnynolimits8-Mar-09 23:46
memberjonnynolimits8-Mar-09 23:46 
GeneralRe: problem with modify size by textbox Pin
Profesjocom9-Mar-09 14:59
memberProfesjocom9-Mar-09 14:59 
GeneralRe: problem with modify size by textbox Pin
jonnynolimits10-Mar-09 3:03
memberjonnynolimits10-Mar-09 3:03 
GeneralExcellent Pin
]Whatever[21-Jan-09 4:53
member]Whatever[21-Jan-09 4:53 
GeneralRe: Excellent Pin
jonnynolimits23-Jan-09 6:46
memberjonnynolimits23-Jan-09 6:46 
GeneralScrollBar Left and Right Pin
leqdangs19-Feb-08 22:23
memberleqdangs19-Feb-08 22:23 
GeneralRe: ScrollBar Left and Right Pin
jonnynolimits22-Feb-08 1:47
memberjonnynolimits22-Feb-08 1:47 
Generalchange Background. Pin
leqdangs10-Jan-08 8:08
memberleqdangs10-Jan-08 8:08 
GeneralRe: change Background. Pin
jonnynolimits11-Jan-08 5:29
memberjonnynolimits11-Jan-08 5:29 
GeneralRe: change Background. Pin
leqdangs11-Jan-08 6:32
memberleqdangs11-Jan-08 6:32 
GeneralRe: change Background. Pin
jonnynolimits14-Jan-08 21:41
memberjonnynolimits14-Jan-08 21:41 
QuestionBroken images? Pin
Fabrizio Camera10-Dec-07 3:37
memberFabrizio Camera10-Dec-07 3:37 
AnswerRe: Broken images? Pin
Francesco Pratolongo10-Dec-07 5:45
memberFrancesco Pratolongo10-Dec-07 5:45 
AnswerRe: Broken images? Pin
jonnynolimits10-Dec-07 5:48
memberjonnynolimits10-Dec-07 5:48 
Questionabout ISerializable interface Pin
aishar21-Nov-07 6:35
memberaishar21-Nov-07 6:35 
AnswerRe: about ISerializable interface Pin
jonnynolimits21-Nov-07 21:51
memberjonnynolimits21-Nov-07 21:51 
QuestionHow can I do that please Pin
aishar21-Nov-07 0:14
memberaishar21-Nov-07 0:14 
AnswerRe: How can I do that please Pin
jonnynolimits21-Nov-07 6:15
memberjonnynolimits21-Nov-07 6:15 
QuestionHow create shape with fixed dimension Pin
etiennegaloup16-Oct-07 22:06
memberetiennegaloup16-Oct-07 22:06 
AnswerRe: How create shape with fixed dimension Pin
jonnynolimits16-Oct-07 22:37
memberjonnynolimits16-Oct-07 22:37 
GeneralRe: How create shape with fixed dimension Pin
etiennegaloup16-Oct-07 23:41
memberetiennegaloup16-Oct-07 23:41 
GeneralRe: How create shape with fixed dimension Pin
jonnynolimits17-Oct-07 0:16
memberjonnynolimits17-Oct-07 0:16 
GeneralRe: How create shape with fixed dimension [modified] Pin
etiennegaloup17-Oct-07 1:32
memberetiennegaloup17-Oct-07 1:32 
GeneralMoving Shape Pin
ymagirdici2-Aug-07 22:28
memberymagirdici2-Aug-07 22:28 
GeneralRe: Moving Shape Pin
ymagirdici8-Sep-07 12:40
memberymagirdici8-Sep-07 12:40 
GeneralRe: Moving Shape Pin
jonnynolimits10-Sep-07 2:02
memberjonnynolimits10-Sep-07 2:02 
GeneralRe: Moving Shape Pin
leqdangs4-Jan-08 18:23
memberleqdangs4-Jan-08 18:23 
GeneralRe: Moving Shape Pin
jonnynolimits6-Jan-08 21:37
memberjonnynolimits6-Jan-08 21:37 
GeneralRe: Moving Shape Pin
leqdangs6-Jan-08 22:21
memberleqdangs6-Jan-08 22:21 
Generalghost shape Pin
Ricardo Fig27-Jul-07 2:34
memberRicardo Fig27-Jul-07 2:34 
GeneralRe: ghost shape Pin
jonnynolimits30-Jul-07 3:16
memberjonnynolimits30-Jul-07 3:16 
Generalrotation Pin
Ricardo Fig25-Jul-07 4:20
memberRicardo Fig25-Jul-07 4:20 
GeneralRe: rotation Pin
jonnynolimits25-Jul-07 22:49
memberjonnynolimits25-Jul-07 22:49 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151126.1 | Last Updated 10 Dec 2007
Article Copyright 2006 by jonnynolimits
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid