420 likes | 567 Views
Visual Basic 程式設計. 講師:戴志華 hana@arbor.ee.ntu.edu.tw 國立台灣大學電機工程研究所. 第十章 圖形化使用者介面 III、 滑鼠、鍵盤與安裝程式. ProgressBar. In Microsoft Window Common Controls 6.0 屬性 Min: 最小值 Max: 最大值 Value: 目前進度的值 Scrolling: ccScrollingStandard ccScrollingSmooth. ProgressBar(cont’d). Option Explicit
E N D
Visual Basic 程式設計 講師:戴志華 hana@arbor.ee.ntu.edu.tw 國立台灣大學電機工程研究所
第十章 圖形化使用者介面III、滑鼠、鍵盤與安裝程式
ProgressBar • In Microsoft Window Common Controls 6.0 • 屬性 • Min:最小值 • Max:最大值 • Value:目前進度的值 • Scrolling: • ccScrollingStandard • ccScrollingSmooth
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
Slider(cont’d) Label4, 5,6 Label 1,2,3 Shape1
Slider(cont’d) 屬性: Shape1: FillStyle=Solid 屬性 Slider1, 2, 3: Min=0 Max=255 TickFrequency=20 SmallChange=1 LargeChange=10 Private Sub Slider1_Change() Label4.Caption = Slider1.Value Shape1.FillColor = RGB(Slider1.Value, _ Slider2.Value, Slider3.Value) End Sub
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
Tabbed Dialog • In Microsoft Tabbed Dialog Control 6.0 • 按右鍵出現屬性對話盒 • Style: • ssStyleTabbedDialog ssStylePropertyPage
Tabbed Dialog(cont’d) • Orientation:Tab的位置 • ssTabOrientation[Top|Bottom|Left|Right] • TabCaption:Tab上的文字 • Tab Count:Tab的總數 • TabsPerRow:每行有幾個Tabs • 用法類似Frame
滑鼠(cont’d) Private Sub Slider1_Change() Form1.MousePointer = Slider1.Value End Sub
滑鼠(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)
滑鼠(cont’d) • Shift • Shift And vbShiftMask • Shift And vbCtrlMask • Shift And vbAltMask • Ex If (shift and vbshiftmask) then …
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 省略
滑鼠(cont’d) • MouseMove(Button As Integer,Shift As Integer,X As Single,Y As Single) • EX: 簡易小畫家
滑鼠(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
鍵盤 • KeyDown(KeyCode As Integer, Shift As Integer) • KeyPress(KeyAscii As Integer)
鍵盤(cont’d) • KeyCode: 鍵盤代碼
鍵盤(cont’d) • ← 37 vbKeyLeft • ↑ 38 vbKeyUp • → 39 vbKeyRight • ↓ 40 vbKeyDown
鍵盤(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
自動轉大寫 • 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
TextBox只能輸入數字 • Private Sub Text1_KeyPress(KeyAscii As Integer) • If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then • KeyAscii = 0 • End If • End Sub IsNumeric ??
封裝及部署精靈 • 封裝(Package) 把一些專案用得到的檔案封裝起來 放置封裝目錄 • 部署(Deploy) 將封裝後的檔案複製到使用者可以用來安裝的地方 執行精靈之前須先產生執行檔~~
封裝及部署精靈(cont’d) VB不得開啟此專案
封裝及部署精靈之外 • Setup Toolkit \Wizards\PDWizard\Setup1 • InstallShield http://www.installshield.com