Está en la página 1de 2

CREAR CONTROLES EN TIEMPO DE EJECUCION

Pegar este codigo en el formulario Agregar un Command1 , 2 TextBox y el siguiente cdigo fuente

Option Explicit ' Cantiadad de PictureBox Dim cantidad As Byte Private Sub Command1_Click() 'Le pasa los valores Top y Left para el control _ creado en tiempo dejecucin CrearPicture CLng(Text1), CLng(Text2) End Sub Private Sub Form_Load() 'Modo de escala en pixeles Me.ScaleMode = vbPixels Command1.Caption = " Crear control " ' Posicin x e y para le Picturebox a crear Text1.Text = 10 Text2.Text = 10 End Sub 'Procedimiento que crea el Picture en tiempo de ejecucin. Private Sub CrearPicture(top As Long, left As Long) Dim MiPicture As PictureBox cantidad = cantidad + 1 Set MiPicture = Controls.Add("VB.PictureBox", "MiPicture" & CStr(cantidad)) 'Le establecemos propiedades al nuevo Picture que se crea With MiPicture ' Hay que hacer el control visible .Visible = True 'dimensiones y posicin .top = top .left = left .Width = 50 .Height = 50

'Le cambia el color por un valor aleatorio .BackColor = RGB(CInt(255 * Rnd), CInt(255 * Rnd), CInt(255 * Rnd)) End With End Sub

También podría gustarte