【发布时间】:2014-12-21 11:31:59
【问题描述】:
我正在使用以下代码在运行时向窗体添加按钮:
Private Sub AddNewButton(ByVal btnName As String, ByVal btnText As String)
Dim myButtons As New VIBlend.WinForms.Controls.vButton
With myButtons
.Size = New Size(200, 60)
.Visible = True
.Location = New Point(55, 33)
.Text = btnText
.Name = btnName
.Font = New Font("Times New Roman", 12, FontStyle.Bold, GraphicsUnit.Point)
End With
AddHandler myButtons.Click, AddressOf btnName & "_Click"
btnsPanel.Controls.Add(myButtons)
End Sub
代码工作正常,但 Vb.net 不允许我使用变量 AddressOf btnName & "_Click" 说 AddressOf operand must be the name of method 分配 AddressOf 子过程,问题是我不知道要创建哪个按钮以及哪个过程是它会调用,我想使用变量分配 AddressOf 过程
有可能还是我有其他选择?
【问题讨论】:
标签: vb.net visual-studio-2012 delegates addressof