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...
In this first article, we have been introduced to the Graphics Object and the Rectangle. We used the DrawPie and FillPie Methods, and looked at how those methods use the Rectangle, StartAngle and SweepAngle settings to create the finished drawing we required.
We employed Brush objects to fill the coloured segments and also to draw the text; a Pen object was used to draw the enclosing lines round the pie segments and bullets.
We saw that the Font is also an object and how we can use its Constructor to create New instances based on our preferences of Font name, size and style.
The DrawString method was used to display text in the font and the various colors of our choosing. We used the FillEllipse and DrawEllipse methods to create circular Colored bullets in the Key.
We have seen that if we put our drawing code in the OnPaint event it will be redrawn whenever the form’s surface has been covered, hidden or otherwise visually affected. We learned that good housekeeping includes disposing of disposable objects when finished with.
So, although the amount of code used in this project is relatively short, it has included several key graphics techniques, including:-
• Brush objects
• DrawEllipse method
• Font object
• Persistence Using OnPaint
• Rectangle object
• Using OnPaint event to Persist the drawing
What we’ve done here of course touches only the very tip of the .Net Graphics iceberg. The power, scope and potential of the graphics tools that are available to you will enable you to bring parts of your application to life in a way that would be difficult - if not impossible - in any other way.
In future articles we will continue to put some of this power to use. Along the way, I hope I will help demystify some of the difficult terms and arcane syntax that makes many developers see Graphics and GDI+ as something of a Black Art. There is so much potential in there, it would be shame not to use at least some it, and - who knows? - in time you may well succeed in graduating from Graphics Apprentice to fully qualified Wizard!