.NET Zone      
 
Smack the Santa: Creating a Game in VB.NET (cont.)

The Smack The Santa Control Form
The source code in Listing 1 shows the code that VB.NET automatically generates as you create the control form. You can copy and paste it over your existing form code or create the form from scratch yourself. Although long, most of the code is self-explanatory. Here's the short explanation.

The control form displays three slider controls with which the player can set:

  • the number of rows
  • the number of columns
  • the speed at which the Santas pop up.
A fourth control, the "Smack Him" button, handles the game generation. I'll describe the game generation process in more detail throughout the rest of this tutorial. Figure 2 shows the control form in the VS.NET designer.


Figure 2: The Smack the Santa control form in the VS.NET designer. At runtime, a player moves the sliders to control the number of Santas on the game form and the speed at which they appear and disappear. The two large buttons containing the Santa images are invisible at runtime.

One thing that isn't immediately apparent from looking at Listing 1 is where the Santa images come from. The two large buttons on the control form hold the images. One button's Image property references the normal Santa image, and the other the "smacked" Santa image. The buttons are invisible (Visible=False) so they don't appear when you run the application. I found the easiest way to create buttons on a dynamic form was to create them on the static form and then programmatically copy the entire control to the new buttons when they instantiate. If you create the form yourself, you'll need to select the images for those two buttons manually. I've included the images with the source code.

In addition to the automatic code, the form contains some event handlers for the sliders. When you move the sliders, these handlers display the results in some text boxes to the right of each of the three controls. The #Region...#End Region lines don't execute, but they let you collapse the code in the IDE and keep them out of the way.

   #Region "Event Handlers"
      Private Sub tbRows_Scroll(ByVal sender As _
         System.Object, ByVal e As System.EventArgs) 
         Handles tbRows.Scroll
   
         lblRows.Text = tbRows.Value
      End Sub
   
      Private Sub tbColumns_Scroll(ByVal sender As _
         System.Object, ByVal e As System.EventArgs) 
         Handles tbColumns.Scroll
   
         lblColumns.Text = tbColumns.Value
      End Sub
   
      Private Sub tbSpeed_Scroll(ByVal sender As _
         System.Object, ByVal e As System.EventArgs) 
         Handles tbSpeed.Scroll
   
         Select Case tbSpeed.Value
            Case 1 : lblSpeed.Text = 
               "Stuck in Chimney"
            Case 2 : lblSpeed.Text = 
               "Full with Cookies"
            Case 3 : lblSpeed.Text = 
               "Sneaky Elf"
            Case 4 : lblSpeed.Text = 
               "Riding the Reindeer"
            Case 5 : lblSpeed.Text = "On Fire!"
          End Select
      End Sub
   #End Region


Introduction

Global Variable Declarations

Introduction The Smack The Santa Control Form Global Variable Declarations
The Popup Mechanism Smack That Bad Boy!  


 





 TALK BACK
Have the problems associated with browser incompatibilities, technology advances, and .NET killed off DHTML and browsers for distributed application development? Let us know in the talk.editors.devx discussion group.
Click here to Join
Get the code for this article

The .NET Framework SDK

.NET Events

Grouping Data in Collections





 
Sponsored Links

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map
Jupiterweb networks

internet.comearthweb.comDevx.comClickZ

Search Jupiterweb:

Jupitermedia Corporation has four divisions:
JupiterWeb, JupiterResearch, JupiterEvents, and JupiterImages

Copyright 2004 Jupitermedia Corporation All Rights Reserved.
Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Jupitermedia Corporate Info | Newsletters | Tech Jobs | E-mail Offers

Copyright Information/Privacy Statement