Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

356 Part III Designing the User Interface


include the System.IO namespace at the top of the code for your form. Next, you
declare a StreamToDisplay variable of the type StreamReader to hold the contents
of the text file, and open the text file by using a specific path. Finally, you read the
contents of the text file into the StreamToDisplay variable by using the ReadToEnd
method, which reads all the text in the file from the current location (the beginning of
the text file) to the end of the text file and assigns it to the Text property of the text box
object. The StreamReader.Close statement closes the text file, and the Select method
removes the selection from the text in the text box object.
You’re finished with the HelpInfo .vb form. Now you’ll add a button object and some code to
the LuckySeven .vb form.

Display the second form by using an event procedure


  1. Click LuckySeven .vb in Solution Explorer, and then click the View Designer button.


The LuckySeven .vb form opens in the Integrated Development Environment (IDE). Now
you’ll add a Help button to the user interface.


  1. Use the Button control to draw a small button object in the lower-right corner of the form.

  2. Use the Properties window to set the button object’s Text property to “Help .”


Your form looks something like this:


  1. Double-click the Help button to display the Button3_Click event procedure in the Code
    Editor.

  2. Type the following program statement:


My.Forms.HelpInfo.ShowDialog()
This statement uses the My namespace (introduced in Chapter 13) to access the forms
active within the current project. As you type the statement, the Microsoft IntelliSense
Free download pdf