Click here to Skip to main content
Click here to Skip to main content

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...

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:

//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

About the Author

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

Comments and Discussions

 
QuestionWhich Design Pattern you are using for Pinmembereg_Anubhava15-Nov-11 18:57 
QuestionHow to Work with Undo Redo Option Pinmembereg_Anubhava23-Jul-10 2:11 
QuestionHow To Rotate Text in 180 Angle Pinmembereg_Anubhava1-Jun-10 23:51 
GeneralText Not Showing Clear Pinmembereg_Anubhava18-May-10 21:36 
GeneralNot Focus Polygon Pinmembereg_Anubhava6-Dec-09 18:14 
GeneralGetting Error :Space Required for this process Pinmembereg_Anubhava27-Nov-09 21:20 
GeneralText Font Error Pinmembereg_Anubhava25-Nov-09 1:10 
GeneralPage Is Out Of Display Pinmembereg_Anubhava11-Nov-09 23:02 
GeneralGenerating Error while Draging Control Pinmembereg_Anubhava24-Aug-09 19:33 
GeneralRe: Generating Error while Draging Control Pinmembereg_Anubhava24-Aug-09 20:07 
GeneralDisplaying "template" and printing "overlay" question. PinmemberDustin Fast16-Apr-09 13:50 
GeneralRe: Displaying "template" and printing "overlay" question. Pinmembernussknacker25-Jun-09 11:37 
GeneralIncredibly Helpful PinmemberDustin Fast16-Apr-09 13:20 
GeneralSome maybe helpful code 'corrections' [modified] Pinmembernussknacker21-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
<code>
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;
}
}
</code>
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.
InitializeComponent();
Initialize();
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
<code>
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.FillRectangle(brush,
this.ClientRectangle);
e.Graphics.ScaleTransform(Zoom, Zoom); // <--- here it is correct
if ( this.Document != null )
{
this.document.Items.Draw(e.Graphics);
}
DrawNetSelection(e.Graphics);
brush.Dispose();
}
</code>
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 PinmemberAntonioMelli4-Jun-08 7:58 
GeneralRe: Add Layers Pinmembernussknacker2-Jul-09 0:57 
Questionhelp for undo and redo functions [modified] Pinmembersan2112018-Apr-08 1:44 
QuestionWould like Rulers that scroll like Word or Visio Pinmembernsaban2-Apr-08 23:37 
GeneralZooming question Pinmember22sas4-Feb-08 19:33 
GeneralCode 39 Pinmemberi22camua11-Jul-07 0:23 
GeneralHelp Pinmemberdragonlil18-Jun-07 19:30 
GeneralRe: Help PinmemberHayder Marzouk19-Jun-07 22:55 
GeneralRe: Help PinmemberHayder Marzouk20-Jun-07 23:39 
GeneralRe: Help Pinmemberdragonlil21-Jun-07 1:15 
QuestionHow to bind textfields to barcodes? Pinmemberphiberx12-Jun-07 15:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web01 | 2.8.140721.1 | Last Updated 30 May 2007
Article Copyright 2007 by Hayder Marzouk
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid