Finally, The Programming Begins!
We have finally come to the point where we're actually going to have to write some new program code to replace the win lines. Remember that you can download the completed program if you have trouble figuring out what the code changes should be.
According to Microsoft, "GDI+ is the successor to GDI, the graphics device interface included with earlier versions of Windows. ... GDI+ is new technology that is included in the Microsoft Windows XP and Windows .NET Server operating systems. It is required as a redistributable for applications that run on the Windows NT 4.0 SP6, Windows 2000, Windows 98, and Windows Millennium Edition operating systems."
So it's a good thing to start becoming familiar with!
Unfortunately, Microsoft also notes that, "The GDI+ C++ class-based interface is designed for use by C/C++ programmers. Familiarity with the Windows graphical user interface and message-driven architecture is required." And keep in mind that many authorities say that it's only vaguely similar to the old GDI.
If you're new to VB.NET, and you don't have a lot of C or C++ experience, you could find the going a bit rough at this point. In brief, one way (the way we're going to do it) is to replace the win lines control array with GDI+ plus coding using our existing controls as the "graphics context" - another new concept. Our friends Cornell and Morrison say, "Although every form or control lets you get at its graphics context, be very careful about doing this. There are subtle hazards." Indeed there are, as we will see.
Here are the steps we're going to follow.
- Create Enum structures with the end points of all of the win lines for use in drawing the lines later.
- Create a GDI+ graphics object in the form and a Pen object in the section of code (the CheckWin procedure) where linWin is used
- Draw the appropriate win line with a Case structure using the same iWin variable as the selection variable.
The "hazards" become apparent when form controls and GDI+ graphics start to share the same space on your monitor. In the final article of this series, we eliminate the controls entirely and do the whole thing in GDI+. But for now, a big part of our purpose is to show you what you get with the Microsoft recommended "upgrade" method.
Next page >
Clear as mud? >
Page 1,
2,
3,
4,
5,
6,
7,
8,
9