Game Development Reference
In-Depth Information
You may have noticed that there are many properties that can be set. One of the
advantages to VB is that you can generally get away with setting the ones you
need and safely ignoring the rest. The Toolbox offers more controls than we need,
and we can safely ignore the extras as well. Curious students will want to learn
more about them by using the help system and the MSDN library. By now, it
should be getting obvious how this project will work.
It is time to write code. Our application needs code to handle three things: events
associated with the NumericUpDown control, events associated with the
RadioButton controls, and gracefully starting up. The easiest way of getting from
a form or a control on a form to the code that handles the events for the form or
the control is to double-click the form or the control. We start with handling the
events related to startup.
Double-click the GameForm form background, taking care not to double-click
one of the controls. Visual Basic brings up a tab labeled GameForm.vb. The code
for the form and all its controls live here. Visual Basic added the skeleton of
the event handler for the form's Load event. The Load event is the most typical
place to put startup code for a form. When the application launches, the form
will be created, and the form's Load event will fire. Let us look carefully at the
code for the form.
All of the code lives between the Class and End Class lines. If you are unfamiliar
with classes, we will expand on them in Chapter 3, ''Finite State Machines
(FSMs).'' For now, all the code for the form goes inside the class. We are more
interested in the event handler.
Private Sub GameForm_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Going from left to right:
n The first keyword is Private . Private conceals this routine, making it visible
only inside the class. You can safely ignore it for now; we will not change it.
n Sub implies that the code does not return a value. If we need to return a
value, we would use the Function keyword instead.
n VB needed a name for this routine, so it used the name of the form and the
name of the event being handled to come up with GameForm_Load . We could
change this name if we wanted to, but the name the system picked is clear
Search Nedrilad ::

Custom Search