0

マウスがまだ押されているときに、フォームの任意のフレームに mouse_down があることを検出したいと考えています。クリックでそれを行う方法は知っていますが、mouse_up の前にキャッチしたいと考えています。

ありがとう

4

1 に答える 1

2

フォームのフレームごとにイベント ハンドラーを作成_MouseDownできます。フレームが多数ある場合は、汎用イベント ハンドラー クラスを作成できます。

クラス モジュールを作成します (例: という名前cUserFormEvents) 。

Public WithEvents Frme As MSForms.frame
Public frm As UserForm

Private Sub Frme_MouseDown( _
 ByVal Button As Integer, _
 ByVal Shift As Integer, _
 ByVal X As Single, _
 ByVal Y As Single)

    ' Put your event code here
    MsgBox Frme.Caption

End Sub

フレームのコレクションを宣言する

Dim mcolFrames As New Collection

このコードをフォームの初期化に含めます

Private Sub UserForm_Initialize()
    Dim ctl As MSForms.Control
    Dim clsEvents As cUserFormEvents

    'Loop through all controls on userform
    For Each ctl In Me.Controls
        'Only process Frames
        If TypeOf ctl Is MSForms.frame Then
            'Instantiate class module and assign properties
            Set clsEvents = New cUserFormEvents
            Set clsEvents.Frme = ctl
            Set clsEvents.frm = Me

            'Add instance to collection
            mcolFrames.Add clsEvents

        End If

    Next ctl

End Sub

これでFrme_MouseDown、フォーム上の任意のフレームで MouseDown が実行されます。で特定のフレームにアクセスしますFrme

于 2011-09-19T05:23:30.827 に答える