?? 09.txt
字號:
---- 字 符 串 型 參 數key 指 定 新 增 按 鈕 的 關 鍵 字, 該 參 數 可 以 省 略。
---- 字 符 串 型 參 數caption 指 定 新 增 按 鈕 的 標 題, 該 參 數 可 以 省 略。
---- 整 型 參 數style 指 定 新 增 按 鈕 的Style 屬 性, 其 合 法 取 值 有5 個, 參 見 前 面Style 屬 性 的 介 紹。 該 參 數 可 以 省 略, 缺 省 時 自 動 取0(tbrDefault)。
---- 參 數image 指 定 給 新 增 按 鈕 載 入 的 圖 象, 圖 象 必 須 是 與 該Toolbar 相 關 聯 的ImageList 控 件 圖 象 庫 中 的 一 個。Image 參 數 可 以 是 一 個 整 數, 對 應ImageList 圖 象 庫 中 某 個 圖 片 的Index 值, 也 可 以 是 一 個 字 符 串, 對 應 圖 片 的 關 鍵 字Key。
---- (2) Remove
---- Remove 方 法 的 語 法 為:
---- Toolbar 控 件 名.Buttons.Remove 按 鈕 的Index 值
---- 或
---- Toolbar 控 件 名.Buttons.Remove 按 鈕 的Key 字 符 串
---- (3) Clear
---- Clear 方 法 的 語 法 為:
---- Toolbar 控 件 名.Buttons.Clear
在 程 序 中 生 成Toolbar
---- 以 上 從 設 計 階 段(design time) 和 程 序 角 度 介 紹 了Toolbar 的 生 成 和 使 用。 下 面 我 們 結 合 實 例 來 看 看 如 何 為 自 己 的 應 用 程 序 添 加 功 能 強 大、 方 便 用 戶 的 工 具 條。
---- 下 面 的 例 子 中, 窗 口 工 具 條 內 有 兩 個 分 別 代 表 打 開 文 件 和 文 件 存 盤 的 按 鈕, 另 外 還 有 一 個 設 置 窗 口 客 戶 區 顏 色 的 組 合 框。 為 免 去 煩 瑣 地 介 紹 工 具 條 的 設 置 過 程, 在 窗 體 制 作 時 僅 僅 加 入 一 個Toolbar 控 件 和 一 個ImageList 控 件, 另 外 在Toolbar 中 加 入 一 個 組 合 框ComboBox。 其 它 所 有 與Toolbar 的 設 置 和 控 制 有 關 的 操 作 都 在 程 序 代 碼 中 實 現, 包 括 為ImageList1 加 入 圖 片 庫、 建 立Toolbar1 和ImageList1 的 關 聯 關 系、 在Toolbar1 中 加 入 按 鈕 并 為 每 個 按 鈕 設 置 屬 性、 對Combo1 進 行 初 始 化 等 等。 下 面 給 出 窗 體Form1 的 程 序 代 碼。
Private Sub Form_Load()
' Create object variable for the ImageList.
Dim imgX As ListImage
' Load pictures into the ImageList control.
Set imgX = ImageList1.ListImages. _
Add(, "open", LoadPicture("Graphics\bitmaps\tlbr_w95\open.bmp"))
Set imgX = ImageList1.ListImages. _
Add(, "save", LoadPicture("Graphics\bitmaps\tlbr_w95\save.bmp"))
Toolbar1.ImageList = ImageList1
' Create object variable for the Toolbar.
Dim btnX As Button
' Add button objects to Buttons collection using the
' Add method. After creating each button, set both
' Description and ToolTipText properties.
Toolbar1.Buttons.Add , , , tbrSeparator
Set btnX = Toolbar1.Buttons.Add(, "open", , tbrDefault, "open")
btnX.ToolTipText = "Open File"
btnX.Description = btnX.ToolTipText
Set btnX = Toolbar1.Buttons.Add(, "save", , tbrDefault, "save")
btnX.ToolTipText = "Save File"
btnX.Description = btnX.ToolTipText
Set btnX = Toolbar1.Buttons.Add(, , , tbrSeparator)
' The next button has the Placeholder style. A
' ComboBox control will be placed on top of this button.
Set btnX = Toolbar1.Buttons.Add(, "combo1", , tbrPlaceholder)
btnX.Width = 1500 ' Placeholder width to accommodate a combobox.
Show ' Show form to continue configuring ComboBox.
' Configure ComboBox control to be at same location as the
' Button object with the PlaceHolder style (key = "combo1").
With Combo1
.Width = Toolbar1.Buttons("combo1").Width
.Top = Toolbar1.Buttons("combo1").Top
.Left = Toolbar1.Buttons("combo1").Left
.AddItem "Black" ' Add colors for text.
.AddItem "Blue"
.AddItem "Red"
.ListIndex = 0
End With
End Sub
Private Sub Form_Resize()
' Configure ComboBox control.
With Combo1
.Width = Toolbar1.Buttons("combo1").Width
.Top = Toolbar1.Buttons("combo1").Top
.Left = Toolbar1.Buttons("combo1").Left
End With
End Sub
Private Sub toolbar1_ButtonClick(ByVal Button As Button)
' Use the Key property with the SelectCase statement to specify
' an action.
Select Case Button.Key
Case Is = "open" ' Open file.
MsgBox "Add code to open file here!"
Case Is = "save" ' Save file.
MsgBox "Add code to save file here!"
End Select
End Sub
Private Sub Combo1_Click()
' Change backcolor of form using the ComboBox.
Select Case Combo1.ListIndex
Case 0
Form1.BackColor = vbBlack
Case 1
Form1.BackColor = vbBlue
Case 2
Form1.BackColor = vbRed
End Select
End Sub
西安市西北工業大學571信箱 況正謙
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -