📄 form1.vb
字号:
Public Class Form1
Inherits System.Windows.Forms.Form
Public ButtonNumber As Int16 '定义一个全程变量用以识别按了哪个按钮
#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
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Private components As System.ComponentModel.IContainer
'Required by the Windows Form Designer
'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 Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents Button6 As System.Windows.Forms.Button
Friend WithEvents Label2 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.Label1 = New System.Windows.Forms.Label
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.Button3 = New System.Windows.Forms.Button
Me.Button4 = New System.Windows.Forms.Button
Me.Button5 = New System.Windows.Forms.Button
Me.Button6 = New System.Windows.Forms.Button
Me.Label2 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Label1
'
Me.Label1.BackColor = System.Drawing.Color.Transparent
Me.Label1.Font = New System.Drawing.Font("宋体", 18.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label1.ForeColor = System.Drawing.Color.Red
Me.Label1.Location = New System.Drawing.Point(48, 152)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(196, 36)
Me.Label1.TabIndex = 0
Me.Label1.Text = "欢迎使用VB.NET"
'
'Button1
'
Me.Button1.BackColor = System.Drawing.Color.Transparent
Me.Button1.ForeColor = System.Drawing.Color.Yellow
Me.Button1.Image = CType(resources.GetObject("Button1.Image"), System.Drawing.Image)
Me.Button1.ImageAlign = System.Drawing.ContentAlignment.MiddleRight
Me.Button1.Location = New System.Drawing.Point(64, 48)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(96, 32)
Me.Button1.TabIndex = 1
Me.Button1.Text = "自动向下移动"
Me.Button1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Button2
'
Me.Button2.BackColor = System.Drawing.Color.Transparent
Me.Button2.ForeColor = System.Drawing.Color.Yellow
Me.Button2.Image = CType(resources.GetObject("Button2.Image"), System.Drawing.Image)
Me.Button2.ImageAlign = System.Drawing.ContentAlignment.MiddleRight
Me.Button2.Location = New System.Drawing.Point(200, 48)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(104, 32)
Me.Button2.TabIndex = 2
Me.Button2.Text = "手动向下移动"
Me.Button2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Timer1
'
'
'Button3
'
Me.Button3.BackColor = System.Drawing.Color.Transparent
Me.Button3.ForeColor = System.Drawing.Color.Yellow
Me.Button3.Image = CType(resources.GetObject("Button3.Image"), System.Drawing.Image)
Me.Button3.ImageAlign = System.Drawing.ContentAlignment.MiddleRight
Me.Button3.Location = New System.Drawing.Point(64, 80)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(96, 32)
Me.Button3.TabIndex = 3
Me.Button3.Text = "自动向左移动"
Me.Button3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Button4
'
Me.Button4.BackColor = System.Drawing.Color.Transparent
Me.Button4.ForeColor = System.Drawing.Color.Yellow
Me.Button4.Image = CType(resources.GetObject("Button4.Image"), System.Drawing.Image)
Me.Button4.ImageAlign = System.Drawing.ContentAlignment.MiddleRight
Me.Button4.Location = New System.Drawing.Point(200, 80)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(104, 32)
Me.Button4.TabIndex = 4
Me.Button4.Text = "手动向左移动"
Me.Button4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Button5
'
Me.Button5.BackColor = System.Drawing.Color.Transparent
Me.Button5.ForeColor = System.Drawing.Color.Yellow
Me.Button5.Image = CType(resources.GetObject("Button5.Image"), System.Drawing.Image)
Me.Button5.ImageAlign = System.Drawing.ContentAlignment.MiddleRight
Me.Button5.Location = New System.Drawing.Point(64, 112)
Me.Button5.Name = "Button5"
Me.Button5.Size = New System.Drawing.Size(96, 32)
Me.Button5.TabIndex = 5
Me.Button5.Text = "自动向右移动"
Me.Button5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Button6
'
Me.Button6.Location = New System.Drawing.Point(200, 112)
Me.Button6.Name = "Button6"
Me.Button6.Size = New System.Drawing.Size(104, 32)
Me.Button6.TabIndex = 6
Me.Button6.Text = "自己编吧"
'
'Label2
'
Me.Label2.BackColor = System.Drawing.Color.Transparent
Me.Label2.Font = New System.Drawing.Font("楷体_GB2312", 15.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label2.ForeColor = System.Drawing.Color.Magenta
Me.Label2.Location = New System.Drawing.Point(64, 8)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(240, 24)
Me.Label2.TabIndex = 7
Me.Label2.Text = "时钟控件应用举例"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
Me.ClientSize = New System.Drawing.Size(368, 270)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Button6)
Me.Controls.Add(Me.Button5)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.Label1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Sub movedown() '自动向下移动
Label1.Top = Label1.Top + 10
If Label1.Top > Me.Height Then Label1.Top = 0
End Sub
Sub moveLeft() '自动向左移动
Label1.Left = Label1.Left - 10
If Label1.Left + Label1.Width < 0 Then Label1.Left = Me.Width
End Sub
Sub moveRight() '自动向右移动
Label1.Left = Label1.Left + 10
If Label1.Left > Me.Width Then Label1.Left = Me.Left - Label1.Width
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Enabled = False
Call movedown()
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
ButtonNumber = 1
Timer1.Interval = 200
Timer1.Enabled = True
End Sub
'Timer1控件Interval时间周期所产生的事件调用此代码段
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Select Case ButtonNumber
Case 1
Call movedown() '调用已经编写好的movedown()过程
Case 3
Call moveLeft() '调用已经编写好的moveleft()过程
Case 5
Call moveRight() '调用已经编写好的moveRight()过程
End Select
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
ButtonNumber = 3
Timer1.Interval = 200
Timer1.Enabled = True
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
ButtonNumber = 5
Timer1.Interval = 200
Timer1.Enabled = True
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Timer1.Enabled = False
Call moveLeft()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -