1、Visual Basic 程式設計,講師:戴志華 hanaarbor.ee.ntu.edu.tw 國立台灣大學電機工程研究所,第十章 圖形化使用者介面III、 滑鼠、鍵盤與安裝程式,3,ProgressBar,In Microsoft Window Common Controls 6.0 屬性 Min:最小值 Max:最大值 Value:目前進度的值 Scrolling: ccScrollingStandard ccScrollingSmooth,4,ProgressBar(contd),Option Explicit Private i As Integer Private Sub Form
2、_Click()i = ProgressBar1.MinTimer1.Interval = 1000 End Sub Private Sub Timer1_Timer()i = i + 1If (i ProgressBar1.Max) ThenTimer1.Interval = 0ElseProgressBar1.Value = iEnd If End Sub,記得要 1.設定Min,Max值 2.加上Timer,5,Slider,6,Slider(contd),7,Slider(contd),Shape1,Label4, 5,6,Label 1,2,3,8,Slider(contd),Pri
3、vate Sub Slider1_Change()Label4.Caption = Slider1.ValueShape1.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,Slider(contd),Private Sub Slider2_Change()Label5.Caption = S
4、lider2.ValueShape1.FillColor = RGB(Slider1.Value, _Slider2.Value, Slider3.Value) End Sub Private Sub Slider3_Change()Label6.Caption = Slider3.ValueShape1.FillColor = RGB(Slider1.Value, _Slider2.Value, Slider3.Value) End Sub,試著將Change改成Scroll,10,Tabbed Dialog,In Microsoft Tabbed Dialog Control 6.0 按右
5、鍵出現屬性對話盒 Style:ssStyleTabbedDialog ssStylePropertyPage,11,Tabbed Dialog(contd),12,Tabbed Dialog(contd),Orientation:Tab的位置 ssTabOrientationTop|Bottom|Left|Right TabCaption:Tab上的文字 Tab Count:Tab的總數 TabsPerRow:每行有幾個Tabs 用法類似Frame,13,滑鼠,14,滑鼠(contd),15,滑鼠(contd),Private Sub Slider1_Change()Form1.MousePo
6、inter = Slider1.Value End Sub,16,滑鼠(contd),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,滑鼠(contd),Shift Shift And vbShiftMask Shift And vbCtrlMask Shift And
7、vbAltMask Ex If (shift and vbshiftmask) then ,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) ThenPrint “Alt”,End IfPrint End Sub Private Sub Form_MouseUp()Prin
8、t “Mouse Up“, Button End Sub,19,滑鼠(contd),MouseMove(Button As Integer,Shift As Integer,X As Single,Y As Single)EX: 簡易小畫家,20,滑鼠(contd),Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)CurrentX = X: CurrentY = YSelect Case ButtonCase vbLeftButtonForeColor = vbBl
9、uePrint “Case vbRightButtonForeColor = vbRedPrint “Case vbMiddleButtonForeColor = BackColorPrint “End SelectEnd Sub,21,鍵盤,KeyDown(KeyCode As Integer, Shift As Integer) KeyPress(KeyAscii As Integer),22,鍵盤(contd),KeyCode: 鍵盤代碼,23,鍵盤(contd),24,鍵盤(contd), 37 vbKeyLeft 38 vbKeyUp 39 vbKeyRight 40 vbKeyDo
10、wn,25,鍵盤(contd),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 I
11、nteger)Print “Key Up“, KeyCode End Sub,26,鍵盤(contd),27,自動轉大寫,Private Sub Text1_KeyPress(KeyAscii As Integer)If KeyAscii = Asc(“a“) and KeyAscii Asc(“z“) ThenKeyAscii = Asc(UCase(Chr(KeyAscii)End IfEnd Sub,28,TextBox只能輸入數字,Private Sub Text1_KeyPress(KeyAscii As Integer)If KeyAscii Asc(“9“) ThenKeyAsc
12、ii = 0End If End Sub,IsNumeric ?,29,封裝及部署精靈,封裝(Package)把一些專案用得到的檔案封裝起來放置封裝目錄 部署(Deploy)將封裝後的檔案複製到使用者可以用來安裝的地方,執行精靈之前須先產生執行檔,30,封裝及部署精靈(contd),31,封裝及部署精靈(contd),32,封裝及部署精靈(contd),VB不得開啟此專案,33,封裝及部署精靈(contd),34,封裝及部署精靈(contd),35,封裝及部署精靈(contd),36,封裝及部署精靈(contd),37,封裝及部署精靈(contd),38,封裝及部署精靈(contd),39,封裝及部署精靈(contd),40,封裝及部署精靈(contd),41,封裝及部署精靈(contd),42,封裝及部署精靈之外,Setup ToolkitWizardsPDWizardSetup1 InstallShieldhttp:/,