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.
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:
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:
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:
BizDraw.Core.Document myDoc = new Document();
myDoc.Name = "Simple test";
myDoc.Height = 25;
myDoc.Width = 50;
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";
BizDraw.Printing.DocumentPrintEngine printEngine = new DocumentPrintEngine();
printEngine.Count = 44;
printEngine.Document = myDoc;
printEngine.Format = PrintFormat.GetFormats();
myDoc = null; printEngine = null;
- 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.
- Article edited and posted to the main CodeProject.com article base
- Bug Fix: Only selected cells in preview mode are printed
- Image support added to the application
- First version published on Code Project