MouseIcon、MousePointer 属性示例
以下示例演示如何指定与特定控件或解决方案对应的鼠标指针。 可以使用 MousePointer 属性分配多个可用鼠标指针之一;或者,可以使用 MousePointer 和 MouseIcon 属性分配自定义图标。
此示例通过下列方式工作:
从 ListBox 中选择鼠标指针,以更改与第一个 CommandButton 关联的鼠标指针。
单击第一个 CommandButton 以将其鼠标指针与第二个 CommandButton 关联。
单击第二个 CommandButton 以为其鼠标指针加载自定义图标。
若要使用此示例,请将此示例代码复制到窗体的声明部分。 确保窗体包含以下内容:
- 两个分别名为 CommandButton1 和 CommandButton2 的 CommandButton 控件。
- 一个名为 ListBox1 的 ListBox 。
注意
此示例使用 Windows) 中的 .ico 文件范围标识的两个图标文件 (,这些文件是使用 LoadPicture 函数加载的。 您应编辑每个 LoadPicture 函数调用以指定驻留在系统上的图标文件。
Private Sub ListBox1_Click()
If IsNull(ListBox1.Value) = False Then
CommandButton1.MousePointer = ListBox1.Value
If CommandButton1.MousePointer = _
fmMousePointerCustom Then
CommandButton1.MouseIcon = _
LoadPicture("c:\msvc20\cdk32\" _
& "samples\circ1\bix.ico")
End If
End If
End Sub
Private Sub CommandButton1_Click()
CommandButton2.MousePointer = CommandButton1.MousePointer
If CommandButton2.MousePointer = fmMousePointerCustom Then
CommandButton2.MouseIcon = CommandButton1.MouseIcon
End If
End Sub
Private Sub CommandButton2_Click()
CommandButton2.MousePointer = fmMousePointerCustom
CommandButton2.MouseIcon = LoadPicture("c:\msvc20\cdk32\samples\push\push.ico")
End Sub
Private Sub UserForm_Initialize()
'Load ListBox with MousePointer choices
ListBox1.ColumnCount = 2
ListBox1.AddItem "fmMousePointerDefault"
ListBox1.List(0, 1) = fmMousePointerDefault
ListBox1.AddItem "fmMousePointerArrow"
ListBox1.List(1, 1) = fmMousePointerArrow
ListBox1.AddItem "fmMousePointerCross"
ListBox1.List(2, 1) = fmMousePointerCross
ListBox1.AddItem "fmMousePointerIBeam"
ListBox1.List(3, 1) = fmMousePointerIBeam
ListBox1.AddItem "fmMousePointerSizeNESW"
ListBox1.List(4, 1) = fmMousePointerSizeNESW
ListBox1.AddItem "fmMousePointerSizeNS"
ListBox1.List(5, 1) = fmMousePointerSizeNS
ListBox1.AddItem "fmMousePointerSizeNWSE"
ListBox1.List(6, 1) = fmMousePointerSizeNWSE
ListBox1.AddItem "fmMousePointerSizeWE"
ListBox1.List(7, 1) = fmMousePointerSizeWE
ListBox1.AddItem "fmMousePointerUpArrow"
ListBox1.List(8, 1) = fmMousePointerUpArrow
ListBox1.AddItem "fmMousePointerHourglass"
ListBox1.List(9, 1) = fmMousePointerHourGlass
ListBox1.AddItem "fmMousePointerNoDrop"
ListBox1.List(10, 1) = fmMousePointerNoDrop
ListBox1.AddItem "fmMousePointerAppStarting"
ListBox1.List(11, 1) = fmMousePointerAppStarting
ListBox1.AddItem "fmMousePointerHelp"
ListBox1.List(12, 1) = fmMousePointerHelp
ListBox1.AddItem "fmMousePointerSizeAll"
ListBox1.List(13, 1) = fmMousePointerSizeAll
ListBox1.AddItem "fmMousePointerCustom"
ListBox1.List(14, 1) = fmMousePointerCustom
ListBox1.BoundColumn = 2
ListBox1.Value = fmMousePointerDefault
MsgBox "ListBox1.Value =" & ListBox1.Value & "."
CommandButton1.MousePointer = ListBox1.Value
End Sub
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。