Presentation is loading. Please wait.

Presentation is loading. Please wait.

Visual Basic 程式設計 講師:戴志華 國立台灣大學電機工程研究所.

Similar presentations


Presentation on theme: "Visual Basic 程式設計 講師:戴志華 國立台灣大學電機工程研究所."— Presentation transcript:

1 Visual Basic 程式設計 講師:戴志華 hana@arbor.ee.ntu.edu.tw 國立台灣大學電機工程研究所

2 第十章 圖形化使用者介面 III 、 滑鼠、鍵盤與安裝程式

3 3 ProgressBar In Microsoft Window Common Controls 6.0 屬性 Min: 最小值 Max: 最大值 Value: 目前進度的值 Scrolling:  ccScrollingStandard  ccScrollingSmooth

4 4 ProgressBar(cont’d) Option Explicit Private i As Integer Private Sub Form_Click() i = ProgressBar1.Min Timer1.Interval = 1000 End Sub Private Sub Timer1_Timer() i = i + 1 If (i > ProgressBar1.Max) Then Timer1.Interval = 0 Else ProgressBar1.Value = i End If End Sub 記得要 1. 設定 Min,Max 值 2. 加上 Timer

5 5 Slider 屬性 Min 最小值 Max 最大值 SmallChange 用方向鍵或滑鼠拖拉的改變 LargeChange 用 PageUp,PageDown 或用滑鼠按 的改變 Value 目前選取值 TickFrequence 刻度的大小

6 6 Slider(cont’d) Orientation ccOrientationHorizontal ccOrientationVertical TickStyle sldBottom sldTopLeft sldBoth sldNoTick

7 7 Slider(cont’d) 事件 Change 在值改變時發生 Scroll 在捲動時發生 Shape1 Label4, 5,6 Label 1,2,3

8 8 Slider(cont’d) Private Sub Slider1_Change() Label4.Caption = Slider1.Value Shape1.FillColor = RGB(Slider1.Value, _ Slider2.Value, Slider3.Value) End Sub 屬性 Slider1, 2, 3: Min=0 Max=255 TickFrequency=20 SmallChange=1 LargeChange=10 屬性: Shape1: FillStyle=Solid

9 9 Slider(cont’d) Private Sub Slider2_Change() Label5.Caption = Slider2.Value Shape1.FillColor = RGB(Slider1.Value, _ Slider2.Value, Slider3.Value) End Sub Private Sub Slider3_Change() Label6.Caption = Slider3.Value Shape1.FillColor = RGB(Slider1.Value, _ Slider2.Value, Slider3.Value) End Sub 試著將 Change 改成 Scroll

10 10 Tabbed Dialog In Microsoft Tabbed Dialog Control 6.0 按右鍵出現屬性對話盒 Style: ssStyleTabbedDialog ssStylePropertyPage

11 11 Tabbed Dialog(cont’d)

12 12 Tabbed Dialog(cont’d) Orientation:Tab 的位置 ssTabOrientation[Top|Bottom|Left|Right] TabCaption:Tab 上的文字 Tab Count:Tab 的總數 TabsPerRow: 每行有幾個 Tabs 用法類似 Frame

13 13 滑鼠 事件處理函式 MouseDown 滑鼠按下 MouseMove 按下後,移動滑鼠 MouseUp 放開滑鼠 屬性 MousePointer 滑鼠指標的圖示 MouseIcon 自訂游標圖案

14 14 滑鼠 (cont’d) vbDefault0vbSizeWE9 vbArrow1vbUpArrow10 vbCrossHair2vbHourGlass11 vbIbeam3vbNoDrop12 vbSizePointer5vbArrowHourglass13 vbSizeNESW6vbArrowQuestion14 vbSizeNS7vbSizeAll15 vbSizeNWSE8vbCustom99

15 15 滑鼠 (cont’d) Private Sub Slider1_Change() Form1.MousePointer = Slider1.Value End Sub

16 16 滑鼠 (cont’d) MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Button: 那個鍵被按  vbRightButton: 2  vbLeftButton: 1  vbMiddleButton: 4 X, Y: 滑鼠的座標值 Shift: 鍵盤特殊鍵的狀況 (Ctrl, Shift, Alt)

17 17 滑鼠 (cont’d) Shift Shift And vbShiftMask Shift And vbCtrlMask Shift And vbAltMask  Ex If (shift and vbshiftmask) then …

18 18 省略 Private Sub Form_Click() Print "Click" End Sub Private Sub Form_DblClick() Print "Double Click" End Sub Private Sub Form_MouseDown(……) Print "Mouse Down", Button, If (Shift And vbAltMask) Then Print “Alt”, End If Print End Sub Private Sub Form_MouseUp(……) Print "Mouse Up", Button End Sub

19 19 滑鼠 (cont’d) MouseMove(Button As Integer , Shift As Integer , X As Single , Y As Single) EX: 簡易小畫家

20 20 滑鼠 (cont’d) Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) CurrentX = X: CurrentY = Y Select Case Button Case vbLeftButton ForeColor = vbBlue Print " █ " Case vbRightButton ForeColor = vbRed Print " █ " Case vbMiddleButton ForeColor = BackColor Print " █ " End Select End Sub

21 21 鍵盤 KeyDown(KeyCode As Integer, Shift As Integer) KeyPress(KeyAscii As Integer) 事件處理函式 KeyDown 鍵盤按下 KeyUp 鍵盤放開 KeyPress 可顯示的鍵才會觸發

22 22 鍵盤 (cont’d) KeyCode: 鍵盤代碼 vbKeyA – vbKeyZ65-90A – Z vbKeyNumpad0 – vbKeyNumpad9 96-105Keypad 0 – 9 vbKey0 – vbKey948-570 – 9 vbKeyF1 - vbKeyF16112-127F1 – F16 vbKeyBack8Backspace vbKeyTab9Tab

23 23 鍵盤 (cont’d) vbKeyReturn13Return vbKeyShift16Shift vbKeyControl17Ctrl vbKeyCapital20Caps Lock vbKeyEscape27Escape vbKeySpace32Space vbKeyInsert45Insert vbKeyDelete46Delete

24 24 鍵盤 (cont’d) ← 37 vbKeyLeft ↑ 38 vbKeyUp → 39 vbKeyRight ↓ 40 vbKeyDown

25 25 鍵盤 (cont’d) Private Sub Form_Click() Cls End Sub Private Sub Form_KeyDown(KeyCode As Integer, _ Shift As Integer) Print "Key Down", KeyCode End Sub Private Sub Form_KeyPress(KeyAscii As Integer) Print "Key Press", KeyAscii, Chr(KeyAscii) End Sub Private Sub Form_KeyUp(KeyCode As Integer, _ Shift As Integer) Print "Key Up", KeyCode End Sub

26 26 鍵盤 (cont’d)

27 27 自動轉大寫 Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii >= Asc("a") and KeyAscii < Asc("z") Then KeyAscii = Asc(UCase(Chr(KeyAscii))) End If End Sub

28 28 TextBox 只能輸入數字 Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii Asc("9") Then KeyAscii = 0 End If End Sub IsNumeric ??

29 29 封裝及部署精靈 封裝 (Package) 把一些專案用得到的檔案封裝起來 放置封裝目錄 部署 (Deploy) 將封裝後的檔案複製到使用者可以用 來安裝的地方 執行精靈之前須先產生執行檔 ~~

30 30 封裝及部署精靈 (cont’d)

31 31 封裝及部署精靈 (cont’d)

32 32 封裝及部署精靈 (cont’d) VB 不得開啟此專案

33 33 封裝及部署精靈 (cont’d)

34 34 封裝及部署精靈 (cont’d)

35 35 封裝及部署精靈 (cont’d)

36 36 封裝及部署精靈 (cont’d)

37 37 封裝及部署精靈 (cont’d)

38 38 封裝及部署精靈 (cont’d)

39 39 封裝及部署精靈 (cont’d)

40 40 封裝及部署精靈 (cont’d)

41 41 封裝及部署精靈 (cont’d)

42 42 封裝及部署精靈之外 Setup Toolkit \Wizards\PDWizard\Setup1 InstallShield http://www.installshield.com


Download ppt "Visual Basic 程式設計 講師:戴志華 國立台灣大學電機工程研究所."

Similar presentations


Ads by Google