2011-09-19 38 views

回答

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 

包括此代码在您的形式initialistion

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

+1

迟到+1。我现在以几种不同的形式使用它,并且它工作得很好。 – Roy

+0

+1我使用相同的方法在PowerPoint用户窗体上为mousedown创建mouseEventListener,而不是在窗体内的每个框架上创建mouseEventListener。完美工作。 – Skovly

相关问题