Click here to Skip to main content
12,509,612 members (51,147 online)
Click here to Skip to main content
Add your own
alternative version


101 bookmarked

BizDraw framework for .NET

, 30 May 2007
Rate this:
Please Sign up or sign in to vote.
A small framework to design and print documents containing shapes, text, images, bar codes...


I have been using Framework .NET since 2003. I have now mastered ADO.NET and data manipulation, and can't imagine working with another framework. However, I was constrained to create a tool for our company users to enable the creation of some special documents that need free-hand painting and special printing features. In the beginning, I was wondering if .NET Framework had the required features enabled to create such applications. That's because I had already experienced similar tries with VB 6 and the result was "NULL."

After a few hours of work and searching over the web, I was impressed with the power of the .NET Framework, especially when having seen the Paint.NET project. So, I decided to create a small -- but very useful, I hope -- framework to satisfy our users and myself. Now I am sure that the .NET Framework is not only about the System.Data namespace, but that there are a lot of other interesting namespaces to discover too. Here is a preview of what we can do with the BizDraw application. I am using it now to create employee badges (used for registration) and also tickets with bar codes for manufacturing products.

Sample image

The framework

I begin with a brief description of the framework namespaces.


The Core namespace contains the Document object that is the core of the framework. You can access the properties and methods of the document programatically to do anything you do with the designer: Adding/moving /changing objects, printing, saving, loading, etc.


Here are all the objects you can insert in a document: Text, Line, Rectangle, Ellipse, BarCode, Free hand drawing. Any new object must be added in this namespace, such as an image object. All of these objects inherit from the DrawObject abstract class. The namespace also contains editors for the drawing object. Generally, each object has its own editor. We found some exceptions though, like for rectangle and ellipse objects, that have the same editor because they have the same properties. I could create a unique editor based on a PropertyGrid, but I preferred this way to have a better user interface. Here is a preview of the Text Object Editor:

Sample image


Tools are needed in the BizDraw designer. Each Drawing Object has its tool to define actions, cursor, etc. Of course, the Pointer tool is a special tool that is used with all objects for selection, resizing and moving operations.


This contains the DocumentManager class that enables Saving/Loading operations. Here, Binary serialization is used. The namespace can be extended to handle export/import operations, i.e. BMP, PDF, Word, etc.


Printing is the most interesting feature in this framework. It's not just a single document print; you can print many documents on the same piece of paper depending on your document size, the paper size and the margins. For example, you can print 44 documents of size 2.5 cm x 5 cm on a single piece of A4 paper. You can also customize which cells you want to print using the mouse in the preview screen. Here is the print preview screen:

Sample image


In the introduction, I said that I am a fan of the System.Data .NET namespace, so it's not surprising that I implemented my own BizDraw.Data namespace. This namespace is used to connect a document to a database. Thus, instead of having static text fields, you can bind text objects with a field from a table or query. The connection string editor and the query editor are far from being Visual Studio 2005 wizards, but they just work fine.


For backward compatibility reasons, I added this namespace to enable use of this framework with COM. So, VB6 developers (as Excel, MFC, etc.) can enjoy the framework without any coding effort. They just have to compile the project within Visual Studio and insert the DocumentSpace control directly from their Visual Studio 6 IDE, just as an OCX. I finished testing it and my VB6 application looks like a .NET application, especially with the .NET 2.0 ToolBar.


Here is a special namesapce for barcodes. I implemented EAN13 bar code -- thanks to Grand Zebu for the code he provided -- but other bar code formats can be easily implemented via the IBarCode interface. Please don't worry about updating the BarCodeEditor form; it's already done using reflection.

Using the framework

This framework provides the necessary controls; all you have to do is drag and drop the DocumentSpace control into your form from the toolbox after adding a reference to BizDraw.dll. You can also use the DocumentArea control instead. In this case, you have to define your menus and catch the necessary events to update the user interface. Another way to use the framework is programatically. You can create a new document, add some objects, save the document and print it to the printer. Here a small example:

//Creating the Document
BizDraw.Core.Document myDoc = new Document();
myDoc.Name = "Simple test";
myDoc.Height = 25;
myDoc.Width = 50;
//Adding a text object
BizDraw.Objects.DrawText myText = new BizDraw.Objects.DrawText();
myText.Location = new PointF(0, 0);
myText.Font = new Font("Verdana", 14);
myText.Text = "Sample text object";
//Saving the document
BizDraw.IO.DocumentManager.Save(myDoc, @"c:\Docs\SampleDoc.bzw");
//Printing 44 copies of the document
BizDraw.Printing.DocumentPrintEngine printEngine = new DocumentPrintEngine();
printEngine.Count = 44;
printEngine.Document = myDoc;
printEngine.Format = PrintFormat.GetFormats()[0]; 
    // gets the first format in the formats directory
//Freeing resources
myDoc = null; // We can also implemebnt IDisposable to the Document class
printEngine = null;

To do

  • Implement Undo/Redo Actions
  • Implement more Barcodes
  • Implement more data providers, as only SQL Server is provided
  • In the framework, I am using measurement units of mm for the user interface, pixels for the screen display and inches for the printers; some modifications must be done to use one measurement unit in all parts


This has been a good opportunity for me to change from classic ADO.NET developments. I hope this framework will be useful for at least one person.


  • 5/30/2007
    • Article edited and posted to the main article base
  • 3/1/2007
    • Bug Fix: Only selected cells in preview mode are printed
    • Image support added to the application
  • 2/2/2007
    • First version published on Code Project


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

Hayder Marzouk
Web Developer
France France
MCSD Asp.Net certified developer

You may also be interested in...


Comments and Discussions

QuestionWhich Design Pattern you are using for Pin
eg_Anubhava15-Nov-11 18:57
membereg_Anubhava15-Nov-11 18:57 
QuestionHow to Work with Undo Redo Option Pin
eg_Anubhava23-Jul-10 2:11
membereg_Anubhava23-Jul-10 2:11 
QuestionHow To Rotate Text in 180 Angle Pin
eg_Anubhava1-Jun-10 23:51
membereg_Anubhava1-Jun-10 23:51 
GeneralText Not Showing Clear Pin
eg_Anubhava18-May-10 21:36
membereg_Anubhava18-May-10 21:36 
GeneralNot Focus Polygon Pin
eg_Anubhava6-Dec-09 18:14
membereg_Anubhava6-Dec-09 18:14 
GeneralGetting Error :Space Required for this process Pin
eg_Anubhava27-Nov-09 21:20
membereg_Anubhava27-Nov-09 21:20 
GeneralText Font Error Pin
eg_Anubhava25-Nov-09 1:10
membereg_Anubhava25-Nov-09 1:10 
GeneralPage Is Out Of Display Pin
eg_Anubhava11-Nov-09 23:02
membereg_Anubhava11-Nov-09 23:02 
GeneralGenerating Error while Draging Control Pin
eg_Anubhava24-Aug-09 19:33
membereg_Anubhava24-Aug-09 19:33 
GeneralRe: Generating Error while Draging Control Pin
eg_Anubhava24-Aug-09 20:07
membereg_Anubhava24-Aug-09 20:07 
GeneralDisplaying "template" and printing "overlay" question. Pin
Dustin Fast16-Apr-09 13:50
memberDustin Fast16-Apr-09 13:50 
GeneralRe: Displaying "template" and printing "overlay" question. Pin
nussknacker25-Jun-09 11:37
membernussknacker25-Jun-09 11:37 
GeneralIncredibly Helpful Pin
Dustin Fast16-Apr-09 13:20
memberDustin Fast16-Apr-09 13:20 
GeneralSome maybe helpful code 'corrections' [modified] Pin
nussknacker21-Jan-09 2:38
membernussknacker21-Jan-09 2:38 
At first: A great program, many thx. I have added here what I have found to get zoom working correctly and also to get scrolling done
I just downloaded the version and looked at the scrolling is missing
So add the following delegate into the code and connect it to the panel1.Scroll event in the designer of the DocumentArea
private void panel1_Scroll(object sender, ScrollEventArgs e) {
if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll) {
this.hRuler1.RulerMargin = this.drawArea1.Left + this.hRuler2.Width;
if (e.ScrollOrientation == ScrollOrientation.VerticalScroll) {
this.hRuler2.RulerMargin = this.drawArea1.Top;
As next you will get a problem when zooming and your document area is bigger then the document space. You cannot scroll to the Left / Top corner because we are centered. So we need to adjust the CenterDrawingArea like <code>

void CenterDrawingArea() {
double UnitSize = (double)((1 / 25.4) * 96.0);
this.drawArea1.Size = new Size(Convert.ToInt32(UnitSize * this.Document.Width * Zoom ), Convert.ToInt32(UnitSize * this.Document.Height * Zoom ));
this.drawArea1.Left = Convert.ToInt32((this.panel1.Width - this.drawArea1.Width) / 2);
this.drawArea1.Left = (this.drawArea1.Left < 0) ? 0 : this.drawArea1.Left;
this.drawArea1.Top = Convert.ToInt32((this.panel1.Height - this.drawArea1.Height) / 2);
this.drawArea1.Top = (this.drawArea1.Top < 0) ? 0 : this.drawArea1.Top;
this.hRuler1.RulerMargin = this.drawArea1.Left + this.hRuler2.Width;
this.hRuler2.RulerMargin = this.drawArea1.Top;
</code>This way we are adjusting in a way where the document is in centre as long as it is smaller then document space and adjusted to Left / Top corner, when bigger. So scrolling works perfectly

Next issue: Try to open DrawArea in design Mode An error occurs because you mustn’t have the ‘Inizialze’ Method Inside of InitializeComponent();
Take it out and add it to the Ctor like <code>
public DrawArea(){
// This call is required by the Windows.Forms Form Designer.
this.KeyDown += new KeyEventHandler(DrawArea_KeyDown);

</code>Now you are able to open graphical esign Mode window without getting an error
The next error is a bit tricky. Just try to do a zoom of 50 % and the background of the drawing area is only a quater of what it should be
Rearrange the paint event in the drawing area in a way that the transformation doesn't work twice
private void DrawArea_Paint(object sender, System.Windows.Forms.PaintEventArgs e) {
//e.Graphics.ScaleTransform(Zoom, Zoom); Undo this here
SolidBrush brush = new SolidBrush(Color.FromArgb(255, 255, 255));
e.Graphics.ScaleTransform(Zoom, Zoom); // <--- here it is correct
if ( this.Document != null )
Thats mainly all I found. Maybe you want to remove that 200 % is added twice to the zoom cmbo, but thats the smallest problem
Hope this helps all a bit
Jonny nut-cracker
modified on Monday, October 11, 2010 7:33 AM

GeneralAdd Layers Pin
AntonioMelli4-Jun-08 7:58
memberAntonioMelli4-Jun-08 7:58 
GeneralRe: Add Layers Pin
nussknacker2-Jul-09 0:57
membernussknacker2-Jul-09 0:57 
Questionhelp for undo and redo functions [modified] Pin
san2112018-Apr-08 1:44
membersan2112018-Apr-08 1:44 
QuestionWould like Rulers that scroll like Word or Visio Pin
nsaban2-Apr-08 23:37
membernsaban2-Apr-08 23:37 
GeneralZooming question Pin
22sas4-Feb-08 19:33
member22sas4-Feb-08 19:33 
GeneralCode 39 Pin
i22camua11-Jul-07 0:23
memberi22camua11-Jul-07 0:23 
GeneralHelp Pin
dragonlil18-Jun-07 19:30
memberdragonlil18-Jun-07 19:30 
GeneralRe: Help Pin
Hayder Marzouk19-Jun-07 22:55
memberHayder Marzouk19-Jun-07 22:55 
GeneralRe: Help Pin
Hayder Marzouk20-Jun-07 23:39
memberHayder Marzouk20-Jun-07 23:39 
GeneralRe: Help Pin
dragonlil21-Jun-07 1:15
memberdragonlil21-Jun-07 1:15 
QuestionHow to bind textfields to barcodes? Pin
phiberx12-Jun-07 15:56
memberphiberx12-Jun-07 15:56 
GeneralGreat Pin
merlin98131-May-07 3:18
membermerlin98131-May-07 3:18 
GeneralNeed your Help Pin
NETA200329-Apr-07 10:43
memberNETA200329-Apr-07 10:43 
GeneralRe: Need your Help Pin
Hayder Marzouk29-Apr-07 22:52
memberHayder Marzouk29-Apr-07 22:52 
GeneralRe: Need your Help Pin
NETA200330-Apr-07 11:43
memberNETA200330-Apr-07 11:43 
Questionthank you, it is a good works Pin
k_hammami20059-Mar-07 0:19
memberk_hammami20059-Mar-07 0:19 
AnswerRe: thank you, it is a good works Pin
Hayder Marzouk9-Mar-07 1:25
memberHayder Marzouk9-Mar-07 1:25 
GeneralRe: thank you, it is a good works Pin
k_hammami200512-Mar-07 3:31
memberk_hammami200512-Mar-07 3:31 
QuestionProblems with creating bar code Pin
str_test2-Mar-07 4:46
memberstr_test2-Mar-07 4:46 
AnswerRe: Problems with creating bar code Pin
Hayder Marzouk4-Mar-07 23:27
memberHayder Marzouk4-Mar-07 23:27 
GeneralRe: Problems with creating bar code Pin
str_test7-Mar-07 8:51
memberstr_test7-Mar-07 8:51 
GeneralRe: Problems with creating bar code Pin
Hayder Marzouk7-Mar-07 19:44
memberHayder Marzouk7-Mar-07 19:44 
GeneralNice ! Pin
Vertyg01-Mar-07 21:16
memberVertyg01-Mar-07 21:16 
GeneralRe: Nice ! Pin
Hayder Marzouk1-Mar-07 21:24
memberHayder Marzouk1-Mar-07 21:24 
GeneralRe: Nice ! Pin
Vertyg01-Mar-07 21:37
memberVertyg01-Mar-07 21:37 
GeneralRe: Nice ! Pin
Hayder Marzouk1-Mar-07 21:48
memberHayder Marzouk1-Mar-07 21:48 
GeneralRe: Nice ! Pin
Vertyg01-Mar-07 21:59
memberVertyg01-Mar-07 21:59 

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
Web02 | 2.8.160929.1 | Last Updated 30 May 2007
Article Copyright 2007 by Hayder Marzouk
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid