Click here to Skip to main content
Click here to Skip to main content
Go to top

Visual Reporting with .NET 2003 (C#)

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

Sample Image

Introduction

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)

Background

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    = 
   System.Drawing.Drawing2D.LinearGradientMode.Vertical;
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         = 
   System.Drawing.Text.TextRenderingHint.AntiAlias;
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  = 
  System.Drawing.Text.TextRenderingHint.SystemDefault;
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", 
                      System.Drawing.Imaging.ImageFormat.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", 
    System.Drawing.Imaging.ImageFormat.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

History

  • 2006-10-18: First version.

License

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

Share

About the Author

No Biography provided

Comments and Discussions

 
Questionproblem with downloading Pinmembernagyist25-May-09 20:01 
AnswerRe: problem with downloading PinmemberVincent DUVERNET (Nolmë Informatique)28-May-09 0:21 
GeneralRe: problem with downloading Pinmembernagyist7-Jun-09 20:32 
GeneralPDFSharp PinmemberPaul Selormey27-Oct-06 23:54 
GeneralRe: PDFSharp PinmemberVincent DUVERNET (Nolmë Informatique)28-Oct-06 5:02 

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
Web04 | 2.8.140926.1 | Last Updated 27 Oct 2006
Article Copyright 2006 by Vincent DUVERNET (Nolmë Informatique)
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid