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