網路城邦
上一篇 回創作列表 下一篇  字體:
KeyPress 的運用
2009/06/16 08:02:12瀏覽1153|回應31|推薦0

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

( 不分類不分類 )
回應 推薦文章 列印 加入我的文摘
上一篇 回創作列表 下一篇

引用
引用網址:https://classic-blog.udn.com/article/trackback.jsp?uid=yangfu&aid=3047003

 回應文章 頁/共 4 頁  回應文章第一頁 回應文章上一頁 回應文章下一頁 回應文章最後一頁

710025
作業
2009/06/25 12:07

高一一班25號

學號710025 黃筱婷

檔名great.exe

夫子(yangfu) 於 2009-07-01 17:19 回覆:
check!

劉冠伶
作業
2009/06/24 23:26

班級:401

座號:31

檔名:980624.exe

夫子(yangfu) 於 2009-07-01 17:19 回覆:
check!

汪宜靜
噗噗噗
2009/06/23 22:04

學號:710007

班級:401

座號:07

檔名:20090623.exe

嘎嘎嘎嘎

夫子(yangfu) 於 2009-07-01 17:20 回覆:
what is  嘎嘎嘎嘎 meaning? don't know?

710142
work
2009/06/23 12:06
work-9.exe   710142  104 22
夫子(yangfu) 於 2009-07-01 17:51 回覆:
please reply follow the rule ! first your number second your name thrid your filename!

張元俊
電腦作業
2009/06/23 10:56

張元俊

710093

403-14

WindowsApplication7.exe

夫子(yangfu) 於 2009-07-16 15:57 回覆:
Sorry! I forget to reply you!

40303
電腦作業
2009/06/23 10:39

403  03

檔名:710083-2.exe

學號:710083

夫子(yangfu) 於 2009-07-16 15:57 回覆:
sorry! forget to reply !

h710084
ok
2009/06/23 10:36

姓名:40304包恆伃

學號:710084

檔名:h7100843

夫子(yangfu) 於 2009-07-16 15:58 回覆:
辛苦了! Your file had been checked!

洪培馨
作業
2009/06/23 10:02

40210洪培馨

學號:710051

檔名:tt.exe

夫子(yangfu) 於 2009-07-16 15:58 回覆:
看過了!但我卻忘記給你回應了!Sorry!

710066
710066-6
2009/06/23 09:52

楊小萱

40227

h710066

檔名710066-6

夫子(yangfu) 於 2009-07-16 15:59 回覆:
Sorry! I had forget to reply you!

710055
homework
2009/06/23 09:44

40215

710055

張書瑜

檔名 710055369.exe

夫子(yangfu) 於 2009-07-16 16:00 回覆:
真抱歉!看過了,卻忘記回應!唉!人年紀大了常會忘東忘西的!
頁/共 4 頁  回應文第一頁 回應文章上一頁 回應文章下一頁 回應文章最後一頁