Windows 2008 R2Windows 2008Windows VistaWindows 7Windows 2003Visual Basic 6Windows 2000Windows XPVisual StudioWindows
如何在 Visual Basic 6.0 中创建笑话点唱机






3.40/5 (13投票s)
一篇关于如何在 Visual Basic 6.0 中创建笑话点唱机的文章

引言
在 Microsoft Visual Basic 6.0 中设计应用程序非常简单直接。指向这里,点击那里,完成了!把它放在窗体上。但说真的,点击左侧工具栏中所需的组件(控件),并在窗体上的适当位置绘制它。
窗体上的组件对齐到矩形网格,使您的应用程序看起来对称。
这个简单的应用程序演示了在 Windows Forms 中创建有趣应用程序的简易性。
列表框
快进一点,我们创建了一个 Windows 窗体,并将列表框、标签和常用对话框放置在窗体上,为了使所有这些控件响应鼠标点击,我们需要在其中添加一些代码。
因此,我们双击任何给定的控件,并将一些代码放置在该控件的事件方法中。
List1_Click() 事件
当鼠标左键按下并位于该 listBox
之上时,会调用 List1_Click()
事件。 一旦索引发生变化,就会调用此方法,它表示用户从包含笑话的文本文件切换到另一个文本文件。
Private Sub List1_Click()
Label1.Caption = ""
JokeLineCount = 0
List2.ListIndex = JokeLineCount
List2.ListIndex = 0
CurrentJokeFile = List1.ListIndex
Label9.Caption = "TimeDelay : " & TimeDelay
LoadJokeFile
DisplayRandomJoke
End Sub
GenerateRandomFile() 方法
调用 GenerateRandomFile()
方法将从文本文件加载笑话到字符串数组中。
Private Sub GenerateRandomFile()
ii = 0
ResetLines
DoneFile = True
Do
CurrentJokeFile = Int(MaxJokeFiles * Rnd)
For ii = 0 To MaxJokeFiles
If (CurrentJokeFile = DoneFiles(ii)) Then
DoneFile = True
End If
If (CurrentJokeFile <> DoneFiles(ii)) Then
DoneFile = False
End If
Next ii
Loop Until (DoneFile = False)
DoneFileCount = DoneFileCount + 1
DoneFiles(DoneFileCount) = CurrentJokeFile
Label11.Caption = "File : " & CurrentJokeFile & _
" UnOpened: " & MaxJokeFiles - DoneFileCount
If (MaxJokeFiles - DoneFileCount < 1) Then
ResetFiles
ResetLines
End If
LoadJokeFile
End Sub
List2_Click() 事件
当鼠标左键按下并位于该 listBox
之上时,会调用 List2_Click()
事件。 一旦索引发生变化,就会调用此方法,它表示用户从一行笑话切换到另一行笑话。
Private Sub List2_Click()
JokeLineCount = List2.ListIndex
DisplayRandomJoke
Label5.Caption = "Current Line : " & JokeLineCount & " of _
" & JokeFile(CurrentJokeFile).MaxLines
Label10.Caption = "Line : " & JokeLineCount & " Unread: _
" & JokeFile(CurrentJokeFile).MaxLines - DoneLineCount
Label9.Caption = "TimeDelay : " & TimeDelay
' UpdateStats
End Sub
DisplayRandomJoke() 方法
调用 DisplayRandomJoke()
方法将从字符串数组中显示一行笑话在标签上。
Private Sub DisplayRandomJoke()
TimerStart = Timer
Label1.Caption = JokeLine(JokeLineCount).Line
TimeDelay = DefaultTimeDelay + (Len(Label1.Caption) * DelayTreshHold)
Label9.Caption = "TimeDelay : " & TimeDelay
Timer1.Interval = TimeDelay
Timer2.Interval = TimeDelay
End Sub
这就是在 Windows Forms 中创建有趣应用程序的简易程度。
感谢阅读。