1 / 36

Visual Basic 程式設計

Visual Basic 程式設計. 講師:戴志華 hana@arbor.ee.ntu.edu.tw 國立台灣大學電機工程研究所. 第九章 圖形化使用者介面 II. CommonDialog. 新增 (參考前一章的內容) Microsoft Common Dialog Control 方法. 選擇顏色- ShowColor. 選擇顏色- ShowColor(cont’d). Private Sub form_click() Dim color As Long CommonDialog1.Flags = cdlCCRGBInit

Download Presentation

Visual Basic 程式設計

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 第九章 圖形化使用者介面II

  3. CommonDialog • 新增 (參考前一章的內容) • Microsoft Common Dialog Control • 方法

  4. 選擇顏色-ShowColor

  5. 選擇顏色-ShowColor(cont’d) Private Sub form_click() Dim color As Long CommonDialog1.Flags = cdlCCRGBInit CommonDialog1.ShowColor color = CommonDialog1.color Line (0, 0)-(100, 100), color, BF End Sub 注意形別,只能是Long 要設定Flag 利用color屬性取得顏色

  6. 選擇顏色-ShowColor(cont’d) • Flags--設定值

  7. 選擇字型-ShowFont

  8. 選擇字型-ShowFont(cont’d) • 執行ShowFont前,設定Flags為 • cdlCFBoth, cdlCFPrinterFonts, cdlCFScreenFonts三選一 • cdlCFEffects允許使用者使用特殊效果 • CommonDialog1.Flags = cdlCFBoth or cdlCFEffects

  9. 選擇字型-ShowFont(cont’d) • 讀取選取字型屬性 • FontSize • FontBold • FontItalic • FontUnderLine • FontName • FontStrikethru

  10. 選擇字型-ShowFont(cont’d) Private Sub form_click() CommonDialog1.Flags = cdlCFBoth or cdlCFEffects CommonDialog1.ShowFont FontSize = CommonDialog1.FontSize FontBold = CommonDialog1.FontBold FontItalic = CommonDialog1.FontItalic FontUnderline = CommonDialog1.FontUnderline FontStrikethru = CommonDialog1.FontStrikethru FontName = CommonDialog1.FontName Print "你好嗎" End Sub Form的屬性

  11. 開啟說明檔-ShowHelp • 設定Help檔檔名 • HelpFile=“檔名” • 設定開啟模式 • HelpCommand=cdlHelpKey • HelpCommand=cdlHelpContents

  12. 開啟說明檔-ShowHelp(cont’d)

  13. 開啟說明檔-ShowHelp(cont’d) Private Sub form_click() CommonDialog1.HelpFile = _ "c:\winnt\help\dao35.hlp" CommonDialog1.HelpCommand = _ cdlHelpKey CommonDialog1.ShowHelp End Sub 請不要照打*^_^*

  14. 開啟檔案-ShowOpen • 出現開啟檔案對話盒 • 傳回使用者輸入(從對話盒點選)的檔案名稱(字串) • 真正開啟的動作自己做(需要其他元件) • ShowSave與ShowOpen相似

  15. 開啟檔案-ShowOpen(cont’d) • 設定Filter • Filter=“描述一|filter1|描述二|filter2……” Ex. Filter=“文字檔|*.txt|圖形檔|*.gif;*.jpg” • 取得檔名 • FileTitle • 取得完整檔名 • FileName

  16. 開啟檔案-ShowOpen(cont’d)

  17. 開啟檔案-ShowOpen(cont’d) • Private Sub form_click() CommonDialog1.Filter = "圖形檔|*.gif;*.jpg;*.jpeg" CommonDialog1.ShowOpen Print CommonDialog1.FileTitle Print CommonDialog1.FileName End Sub

  18. 開啟檔案-ShowOpen(cont’d) • FilterIndex • InitDir • DialogTitle

  19. StatusBar • 新增 • MicroSoft Windows Common Controls • 按右鍵屬性增加Panel

  20. StatusBar(cont’d) 指定順序

  21. StatusBar(cont’d) • Alignment • sbrLeft 置左 • sbrRight置右 • sbrCenter置中 • Bevel • sbrNoBevel平 • sbrInset凹 • SbrRaised凸

  22. StatusBar(cont’d) • Style • sbrText • sbrDate • sbrTime • sbrCaps • sbrNum • sbrIns • sbrScrl 顯示特殊鍵狀態

  23. StatusBar(cont’d) • AutoRaise • sbrNoAutosizeNo Autosizing • sbrSpring彈簧(Extra space divided among panels) • sbrContents依內容調整大小

  24. StatusBar(cont’d) Private Sub form_click() StatusBar1.Panels(1).Text = "你好嗎" End Sub Panel的陣列,從1開始……

  25. ImageList • 按右鍵屬性

  26. ToolBar • 按右鍵屬性 • 在「一般」中,設定ImageList • 也可設定DisabledImageList • 內定值,變灰

  27. ToolBar(cont’d) 指定 ImageList

  28. ToolBar(cont’d) 指定圖示 指定順序

  29. ToolBar(cont’d) • Style • tbrDefault • tbrSeparator空白 • tbrButtonGroup一次只能選一個 • 事件處理函式 • Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)

  30. ToolBar(cont’d) 共有7個按鈕

  31. ToolBar(cont’d) Private Sub Form_click() Toolbar1.Buttons(1).Enabled = False End Sub Private Sub Toolbar1_ButtonClick(ByVal _ Button As MSComctlLib.Button) Select Case Button.Index Case 1 Call …… Case 2 Call …… End Sub 是不是和Windows處理 事件的流程很像呢?

  32. ToolBar(cont’d) • Private Sub Toolbar1_ButtonMenuClick(ByVal ButtonMenu As MSComctlLib.ButtonMenu) Select Case ButtonMenu.Key Case "Document“ Call mnuFileNewDocument Case "Image" Call mnuFileNewImage End Select End Sub

  33. Try It! 方形 圓形 紅 綠 藍

  34. Private Sub Toolbar1_ButtonClick(ByVal _ Button As MSComctlLib.Button) Dim color As Long If (Toolbar1.Buttons(4).Value = _ tbrPressed) Then color = vbRed ElseIf (Toolbar1.Buttons(5).Value = _ tbrPressed) Then color = vbGreen ElseIf (Toolbar1.Buttons(6).Value = _ tbrPressed) Then color = vbBlue End If

  35. Select Case Button.Index Case 1 Cls DrawBox (color) Case 2 Cls DrawCircle (color) End Select End Sub Private Sub DrawBox(color As Long) Line (50, 50)-(100, 100), color, BF End Sub Private Sub DrawCircle(color As Long) Circle (50, 50), 50, color End Sub

  36. Try It!

More Related