Abdullah Diab’s Blog

Your drawings are Objects in GDI+

Hi all .Net developers and programmers.

If you’re a .Net developer or a programmer you must have heard of the Drawing namespace in System namespace, and you maybe used it to draw in your applications.

For those who used them they must have found that moving a single shape in a scene using simple code is not that easy, you’ll have to redraw the whole scene with the shape in its new location, the same thing happens for rotating and scaling a shape, so I had an idea, “Why can’t we just write Rectangle.Move(X,Y) and it moves? Why should I remember every shape coordinates to redraw a small shape in a new position?” so I answered the question.

I developed a small class that lets you manipulate your drawings as Objects, I mean that you can define a rectangle and just write Rectangle.Move(x,y) and it’ll move to the given position without much hard-coding, I defined (Rectangle, Ellipse, Lines), but you can also define your own shape, you just have to inherit the base class (MagicGraphics.Shape) and you’ll have to write your own Render sub (void) and ToString function, and you can add as much as you want of properties.

All the shapes you draw must be placed in a ShapeContainer that handles the drawing according to the Z-Order between shapes.

The following links are for the class and the testing project in VB .Net 2005:

The Class –    The Testing Project.

The testing project shows how to draw, rotate and move shapes, you can start using my class directly after downloading it.

P.S.: The whole project is still Beta but I wanted to share the first build with you.

Have fun, and please tell me what do you think.