jueves, 26 de mayo de 2011

Crear controles en tiempo de ejecucion

Para crear controles en tiempo de ejecución en visual net 2010 lo hacemos de la siguiente manera, en este caso vamos a crear controles picturebox.
Cargamos un form y le agregamos un control button1.
Codigo:



Public Class Form1
    Dim a As Integer


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Generamos el picturebox y le damos algunas propiedades básicas
        For i As Integer = 0 To 3
            Dim pic As New PictureBox
            With pic
                .Width = 150
                .Height = 100
                .Visible = True
                .BackColor = Color.White
                .SizeMode = PictureBoxSizeMode.StretchImage
                .Location = New Point(30, 10 + ((.Top + .Height + 10) * i))
            End With
            'cargamos los controles
            Controls.Add(pic)


            Agregamos unas imágenes para q se vean mejor 
            If a = 0 Then
                pic.Image = Image.FromFile("C:\Users\She\Desktop\te.png")
            End If
            If a = 1 Then
                pic.Image = Image.FromFile("C:\Users\She\Desktop\th.jpg")
            End If
            If a = 2 Then
                pic.Image = Image.FromFile("C:\Users\She\Desktop\Sil.jpg")
            End If
            If a = 3 Then
                pic.Image = Image.FromFile("C:\Users\She\Desktop\tek.jpg")
            End If
            a = a + 1
        Next
    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.StartPosition = FormStartPosition.CenterScreen
        a = 0
    End Sub
End Class



No hay comentarios:

Publicar un comentario