Click here to Skip to main content
15,867,704 members
Articles / Desktop Programming / Windows Forms
Article

BizDraw framework for .NET

Rate me:
Please Sign up or sign in to vote.
4.80/5 (21 votes)
30 May 20075 min read 127.2K   3.2K   102   41
A small framework to design and print documents containing shapes, text, images, bar codes...

Introduction

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.

BizDraw.Core

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.

BizDraw.Objects

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

BizDraw.Tools

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.

BizDraw.IO

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.

BizDraw.Printing

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

BizDrawData

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.

BizDraw.Interop

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.

BizDraw.BarCodes

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:

C#
//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";
myDoc.Items.Add(myText);
//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
printEngine.Print();
//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

Conclusion

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.

History

  • 5/30/2007
    • Article edited and posted to the main CodeProject.com 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

License

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


Written By
Web Developer
France France
MCSD Asp.Net certified developer

Comments and Discussions

 
QuestionWhich Design Pattern you are using for Pin
Anubhava Dimri15-Nov-11 18:57
Anubhava Dimri15-Nov-11 18:57 
QuestionHow to Work with Undo Redo Option Pin
Anubhava Dimri23-Jul-10 2:11
Anubhava Dimri23-Jul-10 2:11 
QuestionHow To Rotate Text in 180 Angle Pin
Anubhava Dimri1-Jun-10 23:51
Anubhava Dimri1-Jun-10 23:51 
GeneralText Not Showing Clear Pin
Anubhava Dimri18-May-10 21:36
Anubhava Dimri18-May-10 21:36 
GeneralNot Focus Polygon Pin
Anubhava Dimri6-Dec-09 18:14
Anubhava Dimri6-Dec-09 18:14 
GeneralGetting Error :Space Required for this process Pin
Anubhava Dimri27-Nov-09 21:20
Anubhava Dimri27-Nov-09 21:20 
GeneralText Font Error Pin
Anubhava Dimri25-Nov-09 1:10
Anubhava Dimri25-Nov-09 1:10 
GeneralPage Is Out Of Display Pin
Anubhava Dimri11-Nov-09 23:02
Anubhava Dimri11-Nov-09 23:02 
GeneralGenerating Error while Draging Control Pin
Anubhava Dimri24-Aug-09 19:33
Anubhava Dimri24-Aug-09 19:33 
GeneralRe: Generating Error while Draging Control Pin
Anubhava Dimri24-Aug-09 20:07
Anubhava Dimri24-Aug-09 20:07 
GeneralDisplaying "template" and printing "overlay" question. Pin
Dustin Fast16-Apr-09 13:50
Dustin Fast16-Apr-09 13:50 
GeneralRe: Displaying "template" and printing "overlay" question. Pin
nussknacker25-Jun-09 11:37
nussknacker25-Jun-09 11:37 
GeneralIncredibly Helpful Pin
Dustin Fast16-Apr-09 13:20
Dustin Fast16-Apr-09 13:20 
GeneralSome maybe helpful code 'corrections' [modified] Pin
nussknacker21-Jan-09 2:38
nussknacker21-Jan-09 2:38 
GeneralAdd Layers Pin
AntonioMelli4-Jun-08 7:58
AntonioMelli4-Jun-08 7:58 
GeneralRe: Add Layers Pin
nussknacker2-Jul-09 0:57
nussknacker2-Jul-09 0:57 
Questionhelp for undo and redo functions [modified] Pin
san2112018-Apr-08 1:44
san2112018-Apr-08 1:44 
QuestionWould like Rulers that scroll like Word or Visio Pin
nsaban2-Apr-08 23:37
nsaban2-Apr-08 23:37 
GeneralZooming question Pin
22sas4-Feb-08 19:33
professional22sas4-Feb-08 19:33 
Hi.

First of all, brilliant work.
I need some help please. When you zoom in, the scrollbars appear. If you scroll vertically or horizontally, the rulers are not scrolling with. I tried putting the rulers in the Documentspace, but then the rulers doesnt scale correctly with zooming.

How can I go about solving this?

Thank you very much!

Thomas
GeneralCode 39 Pin
i22camua11-Jul-07 0:23
i22camua11-Jul-07 0:23 
GeneralHelp Pin
dragonlil18-Jun-07 19:30
dragonlil18-Jun-07 19:30 
GeneralRe: Help Pin
Hayder Marzouk19-Jun-07 22:55
Hayder Marzouk19-Jun-07 22:55 
GeneralRe: Help Pin
Hayder Marzouk20-Jun-07 23:39
Hayder Marzouk20-Jun-07 23:39 
GeneralRe: Help Pin
dragonlil21-Jun-07 1:15
dragonlil21-Jun-07 1:15 
QuestionHow to bind textfields to barcodes? Pin
phiberx12-Jun-07 15:56
phiberx12-Jun-07 15:56 

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.