如何能够在VB中动态添加一个IMAGE控件,而且要能够响应事件
各位大哥小弟想问一下如何能够在VB中动态添加一个IMAGE控件,而且要能够响应事件,各位大哥帮帮忙啊,先谢了
[解决办法]
Option Explicit
Private WithEvents btnObj As CommandButton
Private Sub btnObj_Click()
MsgBox "This is a dynamically added button. "
End Sub
Private Sub Form_Load()
Set btnObj = Controls.Add( "VB.CommandButton ", "btnObj ")
With btnObj
.Visible = True
.Width = 2000
.Caption = "Hello "
.Top = 1000
.Left = 1000
End With
End Sub
[解决办法]
或者
Option Explicit
Dim ctlExtender As VBControlExtender
Private Sub Form_Load()
Set ctlExtender = Controls.Add( "Project1.UserControl1 ", "MyControl ")
With ctlExtender
.Visible = True
.Top = 1000
.Left = 1000
End With
End Sub
Private Sub extObj_ObjectEvent(Info As EventInfo)
'使用 Select Case 编程该控件事件。
Select Case Info.Name
Case "UserName "
'检查用户名值。
MsgBox Info. EventParameters( "UserName ").Value
'现在显示其他情况
Case Else '未知事件
'这里处理未知事件。
End Select
End Sub