⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 09.txt

📁 介绍VB里的各种控件的使用方法,窗口控制,图像编程以及OCX等内容,还提供了一个API集供参考.
💻 TXT
📖 第 1 页 / 共 2 页
字号:
---- 字 符 串 型 参 数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 + -