修改我的”Class Mouse Over”模块,使其适用于所有用户窗体。

huangapple go评论60阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年6月1日 02:45:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76376461.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定