Esto lo ponen en un modulo de clase, no esta muy bien hecho pero puede ir agregandole propiedades segun necesiten,o agregar otro tipo de botones solo chequen el nombre del boton ok?
Option Explicit
Dim WithEvents Boton As CommandButton
Dim WithEvents Caja As TextBox
Enum Tipo
Boton_de_Comando = 0
Caja_de_Texto = 1
End Enum
Public Sub crear_Objeto(Formulario As Form, Objeto As Tipo, Nombre As String, Optional posTop As Long = 0, Optional posLeft As Long = 0, Optional Texto As String = "", Optional Ver As Boolean = True)
On Error GoTo eti
Select Case Objeto
Case 0
Set Boton = Formulario.Controls.Add("VB.CommandButton", Nombre)
Boton.Caption = Texto
Boton.Top = posTop
Boton.Left = posLeft
Boton.Visible = Ver
Case 1
Set Caja = Formulario.Controls.Add("VB.TextBox", Nombre)
Caja.Text = Texto
Caja.Top = posTop
Caja.Left = posLeft
Caja.Visible = Ver
End Select
Exit Sub
eti:
MsgBox Err.Description
Err.Clear
End Sub
Y asi lo mandas llamar
Dimvar As New clsBotones 'clsbotones = nombre que le pusiste al modulo de clase
'y asi lo llamas desde un sub
Private Sub Form_Load()
var.crear_Objeto Form1, Boton_de_Comando, "Boton1", 0, 0, "Hola"
var.crear_Objeto Form1, Caja_de_Texto, "Caja1", 1000, 1000, "Hola"
End Sub
ojala y les sirva, dudas comentarios, quejas postea!Edited by: Zitro