一个简单的Visual Basic程序的创建实例

例:设计一简单应用程序,在窗体上放置1个文本框、2个命令按钮,用户界面如图所示。程序功能是:当单击第一个命令按钮(Command1)“显示”时,在文本框中显示“这是我的第一个VB程序”,命令按钮的标题变为“继续”,再单击该命令按钮,则文本框中显示“请你赐教,谢谢!”,第一个命令按钮的标题又变为“显示”,且第二个命令按钮(Command2)“结束”变为可用。

做下好人把,完整代码:

界面文件Form1.Designer.vb :

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form

'Form 重写 Dispose,以清理组件列表。
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub

'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer

'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改它。
'不要使用代码编辑器修改它。
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.Command1 = New System.Windows.Forms.Button
Me.Command2 = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Command1
'
Me.Command1.Location = New System.Drawing.Point(57, 173)
Me.Command1.Name = "Command1"
Me.Command1.Size = New System.Drawing.Size(75, 23)
Me.Command1.TabIndex = 0
Me.Command1.Text = "显示"
Me.Command1.UseVisualStyleBackColor = True
'
'Command2
'
Me.Command2.Enabled = False
Me.Command2.Location = New System.Drawing.Point(161, 173)
Me.Command2.Name = "Command2"
Me.Command2.Size = New System.Drawing.Size(75, 23)
Me.Command2.TabIndex = 1
Me.Command2.Text = "退出"
Me.Command2.UseVisualStyleBackColor = True
'
'Label1
'
Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.Label1.Location = New System.Drawing.Point(43, 31)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(206, 104)
Me.Label1.TabIndex = 3
Me.Label1.Text = "Label1"
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(292, 270)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Command2)
Me.Controls.Add(Me.Command1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub
Friend WithEvents Command1 As System.Windows.Forms.Button
Friend WithEvents Command2 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label

End Class

代码文件 Form1.vb :

Public Class Form1

Dim clickCount As Int32
Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command1.Click
If (clickCount Mod 2) = 0 Then
Label1.Text = "这是我的第一个VB程序"
Command1.Text = "继续"

Else
Label1.Text = "请你赐教,谢谢!"
Command1.Text = "显示"
End If

If (clickCount > 0) Then
Command2.Enabled = True
End If
clickCount += 1
End Sub

Private Sub Command2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command2.Click
End
End Sub
End Class
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-09-22
界面自己看着给的图,自己做,下面是代码:
Private Sub Form_Load()
Command1.Caption = "显示"
Command2.Caption = "结束"
Command2.Enabled = False
End Sub

Private Sub Command1_Click()
If Command1.Caption = "显示" Then
Text1.Text = "这是我的第一个VB程序"
Command1.Caption = "继续"
Else
Text1.Text = "请你赐教,谢谢!"
Command1.Caption = "显示"
Command2.Enabled = True
End If
End Sub

Private Sub Command2_Click()
End
End Sub本回答被网友采纳