1. Home
  2. Computing & Technology
  3. Visual Basic
The VB.NET Upgrade Wizard
Finally, The Programming Begins!
 Related Resources
• The VB 6 Version:
TicTacToe

• A GDI+ Introduction for Visual Basic 6 Programmers
• A GDI+ Introduction for Visual Basic 6 Programmers
• Source for Upgraded .NET Version
 


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.

  1. Create Enum structures with the end points of all of the win lines for use in drawing the lines later.
  2. Create a GDI+ graphics object in the form and a Pen object in the section of code (the CheckWin procedure) where linWin is used
  3. 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
Explore Visual Basic
By Category
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2009 About.com, a part of The New York Times Company.

All rights reserved.