次の方法で共有


MouseEvent.x プロパティ (Visio)

MouseDownMouseMove、または MouseUp イベントが発生した Microsoft Visio ウィンドウ内の位置の x 座標を返します。 読み取り専用です。

構文

x

MouseEvent オブジェクトを表す変数。

戻り値

VisStatCodes

注釈

x プロパティは、内部図面単位の値を返します。

次のクラス モジュールは、MouseListener という名前のシンク クラスを定義する方法を示しており、作業中のウィンドウでのマウス操作によって発生したイベントをリッスンします。 このクラス モジュールでは、WithEvents キーワードを使用してオブジェクト変数 vsoWindow が宣言されています。 クラス モジュールには、 MouseDownMouseMoveおよび MouseUp イベントのイベント ハンドラーも含まれています。

この例を実行するには、Microsoft Visual Basic for Applications (VBA) プロジェクトに新しいクラス モジュールを挿入し、MouseListener という名前を付けて、モジュールに次のコードを挿入します。

Dim WithEvents vsoWindow As Visio.Window 
 
Private Sub Class_Initialize() 
 
 Set vsoWindow = ActiveWindow 
 
End Sub 
 
Private Sub Class_Terminate() 
 
 Set vsoWindow = Nothing 
 
End Sub 
 
Private Sub vsoWindow_MouseDown(ByVal Button As Long, ByVal KeyButtonState As Long, ByVal x As Double, ByVal y As Double, CancelDefault As Boolean) 
 
 Debug.Print "x is: "; x 
 Debug.Print "y is: "; y 
 
End Sub 
 
Private Sub vsoWindow_MouseMove(ByVal Button As Long, ByVal KeyButtonState As Long, ByVal x As Double, ByVal y As Double, CancelDefault As Boolean) 
 
 Debug.Print "x-position is "; x 
 Debug.Print "y-position is "; y 
 
End Sub 
 
Private Sub vsoWindow_MouseUp(ByVal Button As Long, ByVal KeyButtonState As Long, ByVal x As Double, ByVal y As Double, CancelDefault As Boolean) 
 
 If Button = 1 Then 
 
 Debug.Print "Left mouse button released" 
 
 ElseIf Button = 2 Then 
 
 Debug.Print "Right mouse button released" 
 
 ElseIf Button = 16 Then 
 
 Debug.Print "Center mouse button released" 
 
 End If 
 
End Sub

次に、 ThisDocument プロジェクトに次のコードを挿入します。

Dim myMouseListener As MouseListener 
 
Private Sub Document_DocumentSaved(ByVal doc As IVDocument) 
 
 Set myMouseListener = New MouseListener 
 
End Sub 
 
Private Sub Document_BeforeDocumentClose(ByVal doc As IVDocument) 
 
 Set myMouseListener = Nothing 
 
End Sub

クラスを初期化するためにドキュメントを保存し、アクティブ ウィンドウ内の任意の場所をクリックして MouseDown イベントを発生させます。 ハンドラーによって、Visio ウィンドウ座標空間内のマウスをクリックした場所の x 座標および y 座標がイミディエイト ウィンドウに出力されます。

サポートとフィードバック

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。