Ged Mead (XTab) is a Microsoft Visual Basic MVP who has been working on computer software and design for more than 25 years. His journey has taken him through many different facets of IT. These include training as a Systems Analyst, working in a mainframe software development environment, creating financial management systems and a short time spent on military laptop systems in the days when it took two strong men to carry a 'mobile' system.
Based in an idyllic lochside location in the West of Scotland, he is currently involved in an ever-widening range of VB.NET, WPF and Silverlight development projects. Now working in a consultancy environment, his passion however still remains helping students and professional developers to take advantage of the ever increasing range of sophisticated tools available to them.
Ged is a regular contributor to forums on vbCity and authors articles for DevCity. He is a moderator on VBCity and the MSDN Tech Forums and spends a lot of time answering technical questions there and in several other VB forum sites. Senior Editor for DevCity.NET, vbCity Developer Community Leader and Admin, and DevCity.NET Newsletter Editor. He has written and continues to tutor a number of free online courses for VB.NET developers.
View all articles by Ged Mead...
This article built on the basic skills and techniques covered in Part 1 and also added some new ones. We saw that with a very small amount of code a bar chart can be created completely from scratch.
By calculating the scaling, we ensured that that the bars accurately represented the sales figures, making use of the full height of the drawing area available. Using variables to represent values, such as the margins around the chart, the code is made easier to read and edit.
Using double buffering, the chart was drawn on a Bitmap object out of sight of the user and then the bitmap was applied to a PictureBox once it was complete. This technique reduced flicker and also ensured that once chart was displayed, it will persist (that is, it will be redrawn whenever it has been obscured or changed in some way).
Although the completed code is quite short, several important Graphics Class methods and other drawing skills have been used:-
• Bitmap object
• Create a Graphics object FromImage
• Disposing of Graphics objects
• Drawing on a PictureBox control
• Font object
• Offset method
• Rectangle object
In Part 3, we will return to the Pie Chart and will take user input at runtime to create a chart based on the user’s data and display decisions. The solid colors of the pie will also be replaced with HatchStyles selected by the user.