Click here to Skip to main content
13,091,417 members (60,674 online)
Click here to Skip to main content
Add your own
alternative version


39 bookmarked
Posted 27 Oct 2006

Visual Reporting with .NET 2003 (C#)

Rate this:
Please Sign up or sign in to vote.
Generate report files with your own controls.

Sample Image


Generating report is used very often, CodeProject has some samples, but not always with source code. In my case, I needed to generate some reports with charts. My first article was a first try about it. Another article on XML serialization has been extended to support most of the common objects. At least, for PDF generation, I've tried many solutions (SharpPDF, PDFSharp, Report.NET,iTextSharp) and kept iTextSharp.

Here is a list of controls:

  • Label (text, image, colors, gradients, text formatting, anti-aliasing, markings and clipping)
  • Grid
  • Grid3d
  • Chart
  • Ownerdraw
  • Shape (using GraphicsPath)
  • Table (with cells and rows)


You need to download and install iTextSharp (itextsharp-3.1.5 for this version) in order to run some samples.

Using the code

As usual, many samples are brief descriptions of how to use the article or code. Tutorial 1 to 7 generate a bitmap file and XML file in the Debug or Release output directory which contain the rendering of objects.

All objects are derived from VisualObject and each of these have a collection of children. The root object contains the main rendering information (text, background, margins, clipping, smoothing...).

The main object (VisualReport) contains a root node (VisualObject). Here is the first initialization part (very easy) from Tutorial 1:

// Init main object & root node background attributes
VisualReport    vr = new VisualReport (320,200);//set size ofroot node
vr.RootObject.BackColor        = System.Drawing.Color.WhiteSmoke;
vr.RootObject.BackColor2    = 
   System.Drawing.Color.FromArgb (242,205,242);
vr.RootObject.GradientMode    = 
Here is the hierarchy generation, we're adding two objects to the root node:
// Create a new object and link it to root node
VisualLabel vlLabel            = new VisualLabel ();
vlLabel.Init (90, 10, 200, 90);
vlLabel.Text                = "Hellow World";
vlLabel.TextColor           = 
  System.Drawing.Color.FromArgb (108,91,151);
vlLabel.TextFont            = new System.Drawing.Font("Arial", 
                                  20F, FontStyle.Bold);
vlLabel.TextShadowColor        = System.Drawing.Color.Black;
vlLabel.TextShadowDistanceX    = 1;
vlLabel.TextShadowDistanceY    = 1;
vlLabel.TextSmoothMode         = 
vr.RootObject.AddChild (vlLabel);

// Create a new object and link it to root node
VisualLabel vlLabel2            = new VisualLabel ();
vlLabel2.Init (90, 110, 200, 90);
vlLabel2.Text            = "Hellow World";
vlLabel2.TextColor       = 
  System.Drawing.Color.FromArgb (108,91,151);
vlLabel2.TextFont        = 
  new System.Drawing.Font("Arial", 20F, FontStyle.Bold);
vlLabel2.TextSmoothMode  = 
vr.RootObject.AddChild (vlLabel2);

The final part contains XML exporting and bitmap saving:

// Export to XML file
string strFileName = "./output.xml";
vr.SaveXml (strFileName);
vr.Draw ();
vr.GlobalBitmap.Save ("./output.bmp", 

// Reload XML and save it to compare
VisualReport vr2 = new VisualReport ();
vr2.LoadXml (strFileName);
vr2.SaveXml ("output2.xml");
vr2.Draw ();
vr2.GlobalBitmap.Save ("./output2.bmp", 

Bug Report

There are a few bugs or missing code for the following cases:

  • Cloning objects with hierarchy
  • Drawing charts with specific rendering mode
  • Export to XML doesn't save custom shapes graphic data, image streams, and custom objects


  • 2006-10-18: First version.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

No Biography provided

You may also be interested in...

Comments and Discussions

Questionproblem with downloading Pin
nagyist25-May-09 20:01
membernagyist25-May-09 20:01 
AnswerRe: problem with downloading Pin
Vincent DUVERNET (Nolmë Informatique)28-May-09 0:21
memberVincent DUVERNET (Nolmë Informatique)28-May-09 0:21 
GeneralRe: problem with downloading Pin
nagyist7-Jun-09 20:32
membernagyist7-Jun-09 20:32 
GeneralPDFSharp Pin
Paul Selormey27-Oct-06 23:54
memberPaul Selormey27-Oct-06 23:54 
GeneralRe: PDFSharp Pin
Vincent DUVERNET (Nolmë Informatique)28-Oct-06 5:02
memberVincent DUVERNET (Nolmë Informatique)28-Oct-06 5:02 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170813.1 | Last Updated 27 Oct 2006
Article Copyright 2006 by Vincent DUVERNET (Nolmë Informatique)
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid