MouseIcon 和 MousePointer 属性示例

下例演示了如何指定一个适合特定的控件或场所的鼠标指针。可以用 MousePointer 属性从几个有效的鼠标指针中选择一个;或者用 MousePointer 和 MouseIcon 属性指定一个自定义图标。

按以下方式执行该示例:

  • 从列表框中选择一种鼠标指针,用以改变与第一个命令按钮相关联的鼠标指针。
  • 单击第一个命令按钮,使其鼠标指针与第二个命令按钮相关。
  • 单击第二个命令按钮,为其鼠标指针加载一个自定义图标。

窗体包含:

  • 名为 CommandButton1 和 CommandButton2 的两个命令按钮控件。
  • 名为 LIstBox1 的列表框。

注意 该示例使用了两个图标文件(用 LoadPicture 函数加载;在 Windows 中以 .ico 文件扩展名标识)。要指定常驻系统的图标文件,应编辑每个 LoadPicture 函数的调用。

Sub UserForm_ListBox1_Click()
    If IsNull(UserForm_ListBox1.Value) = False Then
        UserForm_CommandButton1.MousePointer = UserForm_ListBox1.Value
    
        If UserForm_CommandButton1.MousePointer = 99 Then
            UserForm_CommandButton1.MouseIcon = LoadPicture(".\AddinSkin\Icons\winstock.ICO")
        End If
    End If
End Sub

Sub UserForm_CommandButton1_Click()
    UserForm_CommandButton2.MousePointer = UserForm_CommandButton1.MousePointer
    
    If UserForm_CommandButton2.MousePointer = 99 Then
        UserForm_CommandButton2.MouseIcon = UserForm_CommandButton1.MouseIcon
    End If
End Sub

Sub UserForm_CommandButton2_Click()
    UserForm_CommandButton2.MousePointer = 99
    UserForm_CommandButton2.MouseIcon = LoadPicture(".\AddinSkin\Icons\xz.ico")
End Sub

Sub UserForm_Initialize()
    '装入具有 MousePoiter 选择的 ListBox
    UserForm_ListBox1.ColumnCount = 2
        
    UserForm_ListBox1.AddItem "fmMousePointerDefault"
    UserForm_ListBox1.List(0, 1) = 0
    UserForm_ListBox1.AddItem "fmMousePointerArrow"
    UserForm_ListBox1.List(1, 1) = 1
    UserForm_ListBox1.AddItem "fmMousePointerCross"
    UserForm_ListBox1.List(2, 1) = 2
    
    UserForm_ListBox1.AddItem "fmMousePointerIBeam"
    UserForm_ListBox1.List(3, 1) = 3
    UserForm_ListBox1.AddItem "fmMousePointerSizeNESW"
    UserForm_ListBox1.List(4, 1) = 6
    UserForm_ListBox1.AddItem "fmMousePointerSizeNS"
    UserForm_ListBox1.List(5, 1) = 7
    
    UserForm_ListBox1.AddItem "fmMousePointerSizeNWSE"
    UserForm_ListBox1.List(6, 1) = 8
    UserForm_ListBox1.AddItem "fmMousePointerSizeWE"
    UserForm_ListBox1.List(7, 1) = 9
    UserForm_ListBox1.AddItem "fmMousePointerUpArrow"
    UserForm_ListBox1.List(8, 1) = 10
    
    UserForm_ListBox1.AddItem "fmMousePointerHourglass"
    UserForm_ListBox1.List(9, 1) = 11
    UserForm_ListBox1.AddItem "fmMousePointerNoDrop"
    UserForm_ListBox1.List(10, 1) = 12
    UserForm_ListBox1.AddItem "fmMousePointerAppStarting"
    UserForm_ListBox1.List(11, 1) = 13
    
    UserForm_ListBox1.AddItem "fmMousePointerHelp"
    UserForm_ListBox1.List(12, 1) = 14
    UserForm_ListBox1.AddItem "fmMousePointerSizeAll"
    UserForm_ListBox1.List(13, 1) = 15
    UserForm_ListBox1.AddItem "fmMousePointerCustom"
    UserForm_ListBox1.List(14, 1) = 99
    
    UserForm_ListBox1.BoundColumn = 2
    UserForm_ListBox1.Value = 0
   
    UserForm_CommandButton1.MousePointer = UserForm_ListBox1.Value
End Sub

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68