Kick! kick! did you finished your work? please don't forget to upload it to your network storgae and post the link in this article reply! beware of time!
目前PC主要輸入工具是滑鼠與鍵盤。滑鼠是能在螢幕做選取和快速定位的工具,至於鍵盤主要是輸入資料的工具。
程式中靈活運用滑鼠與鍵盤所提供事件,可使得程式生動不少。
譬如:在應用程式中對 TextBox 控制項,判斷到底是按下哪個按鍵?或判斷一些較特殊的按鍵、組合按鍵?或按上、下、左、右鍵來移動物件,按空白鍵不放開時發射子彈,放開按鍵時結束發射子彈,以上這些都必須透過鍵盤事件來處理。
Please completed this program in two week! and upload your execute file to networkstorage and post the link of URL in this article! 請注意時間,因為分數必須在本月底前線上輸入完成,所以在六月二十五日前,請務必將所缺的作業補齊!這樣才不會因有少了作業成品,拉低分數!
code as follow show
【程式碼】 FileName:KeyPress.sln
01 Public Class Form1
02
03 Private Sub Form1_Load(ByVal sender As Object, ByVal e _
As System.EventArgs) Handles Me.Load
04 txtPrice.Text = 0
05 txtQty.Text = 0
06 End Sub
07
08 Private Sub txtId_TextChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles txtId.TextChanged
09 Dim position As Integer = txtId.SelectionStart
10 txtId.Text = txtId.Text.ToUpper()
11 txtId.SelectionStart = position
12 End Sub
14 Private Sub txtId_KeyPress(ByVal sender As System.Object, ByVal e _
As System.Windows.Forms.KeyPressEventArgs) Handles txtId.KeyPress
15 If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
16 txtPrice.Focus()
17 End If
18
19 If txtId.Text.Length < 6 Then
20 If txtId.SelectionStart = 0 Then
21 Dim S As String = e.KeyChar.ToString().ToUpper()
22 If S < "A" Or S > "Z" Then
23 e.Handled = True
24 End If
25 Else
26 If (e.KeyChar < "0" Or e.KeyChar > "9") And _
(e.KeyChar <> vbBack) Then
27 e.Handled = True
28 End If
29 End If
30 Else
31 If e.KeyChar <> vbBack Then
32 e.Handled = True
33 End If
34 End If
35 End Sub
37 Private Sub txtPrice_KeyPress(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles txtPrice.KeyPress
38 If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
39 txtQty.Focus()
40 End If
41 If (e.KeyChar < "0" Or e.KeyChar > "9") And _
(e.KeyChar <> vbBack) Then
42 e.Handled = True
43 End If
44 End Sub
45
46 Private Sub txtPrice_TextChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles txtPrice.TextChanged
47 lblTotal.Text = Val(txtPrice.Text) * Val(txtQty.Text)
48 End Sub
50 Private Sub txtQty_KeyPress(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles txtQty.KeyPress
51 If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
52 Return
53 End If
54 If (e.KeyChar < "0" Or e.KeyChar > "9") And _
(e.KeyChar <> vbBack) Then
55 e.Handled = True
56 End If
57 End Sub
58
59 Private Sub txtQty_TextChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles txtQty.TextChanged
60 lblTotal.Text = Val(txtPrice.Text) * Val(txtQty.Text)
61 End Sub
62
63 End Class