' Project ShowWord ' Display the words from a file in a textbox. Imports System.IO Public Class Form1 Inherits System.Windows.Forms.Form Private reader As StreamReader #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents lblWord As System.Windows.Forms.Label Friend WithEvents btnGetNext As System.Windows.Forms.Button Friend WithEvents btnReset As System.Windows.Forms.Button Friend WithEvents txtWord As System.Windows.Forms.TextBox Private Sub InitializeComponent() Me.txtWord = New System.Windows.Forms.TextBox Me.lblWord = New System.Windows.Forms.Label Me.btnGetNext = New System.Windows.Forms.Button Me.btnReset = New System.Windows.Forms.Button Me.SuspendLayout() ' 'txtWord ' Me.txtWord.BackColor = System.Drawing.Color.White Me.txtWord.Font = New System.Drawing.Font("Microsoft Sans Serif", _ 15.75!, System.Drawing.FontStyle.Bold, _ System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.txtWord.Location = New System.Drawing.Point(48, 32) Me.txtWord.Name = "txtWord" Me.txtWord.ReadOnly = True Me.txtWord.Size = New System.Drawing.Size(192, 31) Me.txtWord.TabIndex = 0 Me.txtWord.Text = "" ' 'lblWord ' Me.lblWord.Font = New System.Drawing.Font("Microsoft Sans Serif", _ 15.75!, System.Drawing.FontStyle.Bold, _ System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblWord.Location = New System.Drawing.Point(104, 80) Me.lblWord.Name = "lblWord" Me.lblWord.Size = New System.Drawing.Size(72, 32) Me.lblWord.TabIndex = 1 Me.lblWord.Text = "Word" ' 'btnGetNext ' Me.btnGetNext.Font = New System.Drawing.Font("Microsoft Sans Serif", _ 15.75!, System.Drawing.FontStyle.Bold, _ System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.btnGetNext.Location = New System.Drawing.Point(48, 128) Me.btnGetNext.Name = "btnGetNext" Me.btnGetNext.Size = New System.Drawing.Size(192, 40) Me.btnGetNext.TabIndex = 2 Me.btnGetNext.Text = "Get Next Word" ' 'btnReset ' Me.btnReset.Font = New System.Drawing.Font("Microsoft Sans Serif", _ 15.75!, System.Drawing.FontStyle.Bold, _ System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.btnReset.Location = New System.Drawing.Point(48, 184) Me.btnReset.Name = "btnReset" Me.btnReset.Size = New System.Drawing.Size(192, 40) Me.btnReset.TabIndex = 3 Me.btnReset.Text = "Reset" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 266) Me.Controls.Add(Me.btnReset) Me.Controls.Add(Me.btnGetNext) Me.Controls.Add(Me.lblWord) Me.Controls.Add(Me.txtWord) Me.Name = "Form1" Me.Text = "Show Words Project" Me.ResumeLayout(False) End Sub #End Region Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load btnReset.PerformClick( ) txtWord.SelectionLength = 0 End Sub ' Get next word from file. Private Sub btnGetNext_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles btnGetNext.Click If reader.Peek( ) > -1 Then txtWord.Text = reader.ReadLine( ) Else txtWord.Clear( ) End If End Sub Private Sub btnReset_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles btnReset.Click reader = Nothing reader = New StreamReader("Words.txt") btnGetNext.PerformClick( ) End Sub End Class