Well I was really busy actually - finding a job, moving countries, dealing with movers, insurance claims, doctors, flat hunting and all that on top of a really challenging new job (no worries, I am surviving!).
So here I am, finally tackling something new! Blame the bookshop Foyles, where I found this Visual C# programming book by Jonathan S. Harbour and immediately started playing with WindowsForms. It took me a while, as the book clearly forgets to tell you how to actually open new projects (good thing author has a forum!!)
Anyway, the first project is familiarizing yourself with drawing shapes and bitmaps with GDI+. The structure of the code is fairly easy once you’ve understood it, even if you have never looked at C# before.
The code is divided in easily identified categories.
At the top you have your global statements, where you create your main objects.
This is followed by the Form1_Load section, which allows you to define the settings of your Form. In this case, the author uses the PictureBox control to blend with the Form1 frame and define the canvas. It is in the section as well that the settings for the Bitmap surface and the graphics device, as well as the random generator.
Think of the Bitmap as a polaroid taken after each change. It is independent from the PictureBox and can be saved. The graphics device is defined as the tool that will impact on the bitmap surface.
After the Form1_Load, it is time to work on the graphics device function, which gets its own section. This first project proposes to draw lines in random colours and widths. The colour of the line is defined by randomly assigning values to each segment the ARGB scale. A Pen object is used to gather the coordinates defining the beginning and end of the line.
A Timer object is also used in this particular instance. It defines the interval at which a new line is drawn. This object is also part of the Form1_Load section.
And finally, the code closes with a “free memory” object. This object basically throws away the data stored regarding the graphics device, the surface and the timer and is good practice when running code that uses a lot of memory.
I’m not pasting the whole code here but I thought the section on creating the graphics device was the most interesting:
![]()