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 支援與意見反應。