我需要将一个参数(ref或val不重要)传递给与在运行时生成的控件(复选框)相关联的事件。我似乎无法找到方法。 (我必须承认,我甚至尝试了一些肮脏的公开声明......无济于事) 另外说明如何从事件中访问控件的属性?
我生成复选框的部分:
For Each distinctClientList In Range("DA3:DA" & LastRow).Cells
Dim MaTextBox As Object
Set MaTextBox = Client_picking.Controls.Add("Forms.TextBox.1")
With MaTextBox
.Text = CStr(distinctClientList.Value)
.Left = 20
.top = topref + (20 * Client_picking.i)
.Width = 90:
.Height = 20
End With
Dim MaCheckBoxfile As Object
Set MaCheckBoxfile = Client_picking.Controls.Add("Forms.CheckBox.1")
With MaCheckBoxfile
.Caption = "fichier"
.Left = 140
.top = topref + (20 * Client_picking.i)
End With
ReDim Preserve ButArray(1 To Client_picking.i)
Set ButArray(Client_picking.i).butEvents() = MaCheckBoxfile
Client_picking.i = Client_picking.i + 1
Next
我的处理程序
Public WithEvents butEvents As MSForms.CheckBox
Private Sub butEvents_click()If Checked Then
MsgBox "checked" & /*This is where i would put my parameter... IF I HAD ONE!*/
End If
End Sub
答案 0 :(得分:1)
控件在类中分配给名为butEvents的变量,因此您可以通过它访问其所有属性:
butEvents.BackColor = vbRed