英文:
Modify my Class Mouse Over module to work with all userforms
问题
创建一个按钮的MouseOver事件模块类,可用于所有用户窗体
我创建了一个按钮的Mouse Over模块类,它在用户窗体"UF_Valeur"上起作用。
但我想将用户窗体作为参数添加到Classe1中,以便我可以在所有用户窗体上使用它。
我的用户窗体"UF_Valeur"有4个控件。
Btn100_00
Btn100_01
Btn101_00
Btn101_01
在模块Classe1中
Option Explicit
Public WithEvents dImages As MSForms.Image
Private Sub dImages_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
UF_Valeur.Controls(Left(dImages.Name, 6) & "_00").Visible = False
UF_Valeur.Controls(Left(dImages.Name, 6) & "_01").Visible = True
End Sub
在用户窗体"UF_Valeur"中
Option Explicit
Dim dArray() As New Classe1
Sub List_Controls()
Dim dImage As Object, Ctrol As control, i As Integer
i = 1
For Each Ctrol In Me.Controls
If Ctrol.Tag = "zero" Then
Set dImage = Me.Controls(Ctrol.Name)
ReDim Preserve dArray(1 To i)
Set dArray(i).dImages = dImage
i = i + 1
End If
Next Ctrol
End Sub
Private Sub UserForm_Activate()
List_Controls
End Sub
Sub Userform_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim Ctrol As control
For Each Ctrol In Me.Controls
If Ctrol.Tag = "zero" Then Me.Controls(Ctrol.Name).Visible = True
End If
Next Ctrol
End Sub
英文:
Create module a Class of MouseOver event for buttons to use with all userforms
I create a module Class Mouse Over for my buttons and It works on the userform "UF_Valeur".
But I want to add userform as parameter in the Classe1 so that I can use it on all userforms.
My Userfom "UF_Valeur" have 4 controls.
Btn100_00
Btn100_01
Btn101_00
Btn101_01
In Module Classe1
Option Explicit
Public WithEvents dImages As MSForms.Image
Private Sub dImages_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
UF_Valeur.Controls(Left(dImages.Name, 6) & "_00").Visible = False
UF_Valeur.Controls(Left(dImages.Name, 6) & "_01").Visible = True
End Sub
In Userform "UF_Valeur"
Option Explicit
Dim dArray() As New Classe1
Sub List_Controls()
Dim dImage As Object, Ctrol As control, i As Integer
i = 1
For Each Ctrol In Me.Controls
If Ctrol.Tag = "zero" Then
Set dImage = Me.Controls(Ctrol.Name)
ReDim Preserve dArray(1 To i)
Set dArray(i).dImages = dImage
i = i + 1
End If
Next Ctrol
End Sub
Private Sub UserForm_Activate()
List_Controls
End Sub
Sub Userform_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim Ctrol As control
For Each Ctrol In Me.Controls
If Ctrol.Tag = "zero" Then Me.Controls(Ctrol.Name).Visible = True
Next Ctrol
End Sub
答案1
得分: 0
在你的类中,你有一个对图像控件的引用,因此你可以通过控件的 Parent
属性引用包含的表单。
例如:
dImages.Parent.Controls(Left(dImages.Name, 6) & "_00").Visible = False
英文:
Within your class you have a reference to the Image control, so you can reference the containing form via the control's Parent
property.
Eg.
dImages.Parent.Controls(Left(dImages.Name, 6) & "_00").Visible = False
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论