Private Sub Command1_Click() Dim tt As Label Set tt = Me.Controls.Add("VB.Label", "lblTest") With tt .Visible = True .Caption = "test" End With End Sub
Private WithEvents cmd As CommandButtonPrivate Sub cmd_Click() MsgBox "clicked" End SubPrivate Sub Form_Load() Set cmd = Me.Controls.Add("vb.commandbutton", "ctrl") With cmd .Move 0, 0, ScaleWidth / 5, ScaleHeight / 5 .Caption = "CommandButton" .Visible = True End With End Sub
to : XuyfLy(XuyfLy) 因为我每次都会不定量的动态生成,所以预先把控件放上的话,我就不能掌握各控件的Name,不过还是谢谢您^_^
Dim tt As Label
Set tt = Me.Controls.Add("VB.Label", "lblTest")
With tt
.Visible = True
.Caption = "test"
End With
End Sub
MsgBox "clicked"
End SubPrivate Sub Form_Load()
Set cmd = Me.Controls.Add("vb.commandbutton", "ctrl")
With cmd
.Move 0, 0, ScaleWidth / 5, ScaleHeight / 5
.Caption = "CommandButton"
.Visible = True
End With
End Sub
因为我每次都会不定量的动态生成,所以预先把控件放上的话,我就不能掌握各控件的Name,不过还是谢谢您^_^