ชุดฟังก์ชั่นการอ่านการกดคีย์ (VB6.0)Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyF1 Then
num = num + 1
Label1.Caption = Format(num, "00#")
ElseIf KeyCode = vbKeyF2 Then
num = num + 1
Label2.Caption = Format(num, "00#")
End If
End Sub
แต่จะทำงานได้ก็ต่อเมื่อ พร๊อพเปอร์ตี้ของ Form ที่กำลังทำงานอยู่ในส่วนของ KeyPreveiw=Ture เท่านั้น
ชุดฟังก์ชั่นการอ่านการกดคีย์ (VB2010)[code]
Public Class Form1
Dim nums As Integer
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.F1 Then
nums = nums + 1
Label1.Text = Format(nums, "000")
Else
nums = nums + 1
Label2.Text = Format(nums, "000")
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
KeyPreview = True
End Sub
End Class
จัดตำแหน่งโดยใช้ขนาดจอมาคำนวณ VB2010
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Top = Screen.PrimaryScreen.Bounds.Height / 2
Me.Left = Screen.PrimaryScreen.Bounds.Width / 2
End Sub