Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  .NET Newbie  »  Chart Success: Second Helpings of Pie. Part 3
 »  Home  »  Windows Development  »  Graphics  »  Chart Success: Second Helpings of Pie. Part 3
Chart Success: Second Helpings of Pie. Part 3
by Ged Mead | Published  03/23/2005 | .NET Newbie Graphics | Rating:
Ged Mead

Ged Mead (XTab) has been around computers since the 1980's when the first affordable home computers came on the market. His journey from that very first Dragon 32 to the present has taken him through many different facets of the IT Industry. These include formal training as a Systems Analyst, employment in a mainframe software development environment, and a short time spent demonstrating rugged military IT systems in the days when it took two strong men to carry a 'mobile' system.

His most rewarding challenge was the creation of a financial management system for a large organisation.

Now based in an idyllic lochside location in the West of Scotland, he is currently involved in a range of development projects, whenever he can drag his gaze away from the stunning surrounding views, that is!

Ged is a Microsoft MVP, Senior Editor for DevCity.NET, vbCity Developer Community Leader and Admin, Helper of the Month competition winner and DevCity.NET newsletter Editor.

 

View all articles by Ged Mead...
Setting Out The Form

Skeleton Layout 
   Because these articles are aimed at showing you how to use the Graphics Classes, I will skim over most of the non-graphics stuff wherever I can. So, to help shortcut the process of creating the Windows Form and its controls, I have included a project containing a skeleton form (i.e. it contains the controls, but none of the graphics code). You will find it in the folder named "Skeleton" in the attached zip file.

  The form and its controls looks like this:

 

Of course, if you prefer to build the form yourself, go ahead. I will let you know the names used and other details for the controls where these are significant to the code as we come to them.

Let's get Coding
Insert these statements at the top of the form:

    Option Strict On
    Imports System.Drawing.Drawing2D
    Imports System.Collections

As in the previous articles, a Structure is used to compartmentalise the data and an arraylist to store it. It's quick and easy and should be very familiar by now.

  Structure GraphData
    Dim Name As String
    Dim Amount As Decimal
    Dim Clr As Color
    Dim Pattern As HatchStyle
  End Structure

    ' Arraylist to hold data as it is input by user
    Dim UserData As New ArrayList

    This Structure is similar to the one created in Part 1 - the first three fields (Name, Amount and Clr) representing the same elements. The additional item (Pattern) will hold the user's choices of HatchStyles.

    The framework offers a range of more than 50 HatchStyles - basically, they offer a choice of coloured shadings. The image below shows a few sample styles:

 

 

Temporary Variables
    From the work we did in Parts 1 and 2, you will know that we will create instances of our User Defined Value Type (GraphData) and assign values to each of the four fields. In this version we will let the user do this at run time.

    We also need a couple of variables to hold the values of the Color and HatchStyle elements temporarily while the user is choosing the rest of the settings. Add these to the declarations area where you instantiated the arraylist:

    Dim clrPicked As Drawing.Color = Color.Black
    Dim hatchPicked As HatchStyle = HatchStyle.DarkHorizontal

    You will see that default values (Black and DarkHorizontal) are included in the code above. Doing this avoids errors which would otherwise arise if the user forgets to select either of these elements.

 

Comments    Submit Comment

Comment #1  (Posted by an unknown user on 03/25/2005)
Rating
The good is getting even better. Cool job, Ged.
 
Comment #2  (Posted by an unknown user on 04/19/2005)
Rating
an amazing series of articles! It difficult to explain in such a simple way has you did. Thanks
 
Comment #3  (Posted by Ronan on 04/13/2006)
Rating
Hi i have read these tutorials and am looking your help.
I am trying to develop a pie chart interface in Visual Studio 2003 for a PDA (Smart Device Application) and tried your code. however it is not compatible as it does not recognise the drawPie and FillPie commands, etc. Do you have an example i could use to help me for this?
Thank you, Ronan
 
Comment #4  (Posted by PeteB on 05/22/2006)
Rating
reall useful.
 
Comment #5  (Posted by an unknown user on 12/08/2006)
Rating
Very Educative
 
Comment #6  (Posted by an unknown user on 08/27/2007)
Rating
clear / simple
 
Sponsored Links