Chapter 14 Managing Windows Forms and Controls at Run Time 355
- Double-click OK to display the Button1_Click event procedure in the Code Editor.
- Type the following program statement:
Me.DialogResult = DialogResult.OK
The HelpInfo .vb form acts as a dialog box in this project because the Lucky Seven form
opens it using the ShowDialog method. After the user has read the Help^ information
displayed by the dialog box, he or she will click OK, which sets the DialogResult
property of the current form to DialogResult .OK. (The Me keyword is used here to refer
to the HelpInfo .vb form, and you’ll see this shorthand syntax from time to time when
a reference is being made to the current instance of a class or structure in which the
code is executing .)
DialogResult .OK is a Visual Basic constant that indicates the dialog box has been closed
and should return a value of “OK” to the calling procedure. A more sophisticated
dialog box might allow for other values to be returned by parallel button event
procedures, such as DialogResult.Cancel, DialogResult.No, and DialogResult.Yes.
When the DialogResult property is set, however, the form is automatically closed.
- At the top of the Code Editor, type the following Imports statement above the Public
Class declaration:
Imports System.IO
This statement makes it easier to reference the StreamReader class in your code. The
StreamReader class isn’t specifically related to defining or using additional forms—I’m
just using it as a quick way to add textual information to the new form I’m creating. - Display the HelpInfo .vb form again, and then double-click the form background.
The HelpInfo_Load event procedure appears in the Code Editor. This is the event
procedure that runs when the form is first loaded into memory and displayed on
the screen.
- Type the following program statements:
Dim StreamToDisplay As StreamReader
StreamToDisplay = _
New StreamReader("c:\vb10sbs\chap14\lucky seven help\readme.txt")
TextBox1.Text = StreamToDisplay.ReadToEnd
StreamToDisplay.Close()
TextBox1.Select(0, 0)
Rather than type the contents of the Help file into the Text property of the text box
object (which would take a long time), I’ve used the StreamReader class to open, read,
and display an appropriate Readme .txt file in the text box object. This file contains
operating instructions and general contact information.
The StreamReader class was introduced in Chapter 13, “Exploring Text Files and
String Processing,” but you might not have experimented with it yet. As you learned,
StreamReader is a .NET Framework alternative to opening a text file with the
My.Computer.FileSystem object. To make it easier to use StreamReader in code, you