• 1000 Код функций, как показано ниже;
Option Explicit
Public col_button As Collection
Public userform_index As UserForm
Public temp_ctl
Sub Run()
Main_Page.Show
End Sub
Function Button_Hover()
Set col_button = New Collection '' Crate a collection which carry item in it.
For Each temp_ctl In userform_index.Controls '' Checking every toolbox item in exist userform
If Len(temp_ctl.Name) = 7 And TypeName(temp_ctl) = "Image" Then
'' ^^I have image called button1 also button1_hover. I sparate that with it. (takes only button1)^^
col_button.Add getHover(temp_ctl) '' used interested image in function called gethover
End If
Next
col_button.Add getHover(userform_index) '' used userform in gethover function
End Function
Private Function getHover(temp_ctl) '' this func set hover as image or userform.
Dim temp_hover As New hover
If TypeName(temp_ctl) = "Image" Then
Set temp_hover.btnimg = temp_ctl
Else
Set temp_hover.btnform = temp_ctl
End If
Set getHover = temp_hover
End Function
И ... Большой :) класс, называемый hover, делает l oop каждый раз, когда я заставляю мышь перемещаться по изображению или пользовательской форме.
Option Explicit
Public WithEvents btnimg As MSForms.Image
Public WithEvents btnform As MSForms.UserForm
Public button_index As Integer
Public button_count As Integer
Sub btnimg_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
button_index = Right(btnimg.Name, 1) ''gettin button index as i did. (Exp: button1 to 1)
button_count = (col_button.Count) - 1 '' gettin button count decrease userform.
userform_index.Controls("button" & button_index).Visible = False '' (Exp: button1.visible =false)
userform_index.Controls("button" & button_index & "_hover").Visible = True '(Exp: button1_hover.visible =True)
End Sub
Sub btnform_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
button_count = (col_button.Count) - 1
For button_index = 1 To button_count '' Set all button with no hover visible and make hovers invisible.
userform_index.Controls("button" & button_index).Visible = True
userform_index.Controls("button" & button_index & "_hover").Visible = False
Next
End Sub
Конечный результат; введите описание изображения здесь
Он работает нормально, но мне нужно обновить более 9 кнопок: D. но у меня это работает прямо сейчас.