← Foro de Visual Basic

labels dinamicas

Hilo en el foro de Visual Basic · 21 de Septiembre del 2005 · 3 respuestas
harielo21 de Septiembre del 2005
Pregunta
necesito crear etiquetas (labels) en forma dinamica (en tiempo de ejecucion). se puede hacer? cómo?.

Desde ya.. muchas gracias

Respuestas 3

mvallejos21 de Septiembre del 2005
El modo que conozco es

Colocas una label, con index 0, a modo de elemento inicial de un array de labels. Supongamos que tenemos una Label1 con Index = 0, así creamos una instancia

Dim Indice as Integer

' ver cuál es el proximo indice
Indice = Label1.Ubound + 1
Load Label1(Indice)
' colocarla en alguna posicion, se crean en el mismo
' lugar que el del elemento inicial
Label1(Indice).Left = PosX
Label1(Indice).Top = PosY
Label1(Indice).Caption = ..........
Label1(Indice).Visible = true

La tenés que poner visible ya que se crean invisibles

Probalo y cualquier problema avisame

Saludos











gucesoft21 de Septiembre del 2005
UTILIZA LA INSTRUCCION "LOAD" DE VISUAL BASIC.
PARA QUE FUNCIONE LO UNICO QUE TIENES QUE HACER ES ESTABLECER LA PROPIEDAD "Index" DEL OBJETO QUE DESEAS DUPLICAR A (0)...
EJEMPLO.
SITUA UN CONTROL Label1(0) EN UN FORMULARIO EL CODIGO QUE SIGUE PODRIAS SITUARLO EN EL EVENTO LOAD DEL FORMULARIO O EN EL EVENTO CLICK DE UN CONTROL COMMAND
...
Dim nCnt As Integer

For nCnt = 0 To 5
If nCnt >= 1 Then
Load Label1(nCnt)
Label1(nCnt).Caption = "Etiqueta " & Format(nCnt + 1, "00")
'+++ ESTABLEMOS SU POSICION
Label1(nCnt).Left = Label1(nCnt - 1).Left
Label1(nCnt).Top = Label1(nCnt - 1).Top + Me.ScaleY(6, vbMillimeters, vbTwips)
End If
'+++ ESTABLECEMOS SU ANCHO EN RELACION CON EL TEXTO DEL CAPTION
If Label1(nCnt).Width < Me.TextWidth(Label1(nCnt).Caption) + Me.ScaleX(6, vbMillimeters, vbTwips) Then
Label1(nCnt).Width = Me.TextWidth(Label1(nCnt).Caption) + Me.ScaleX(6, vbMillimeters, Me.ScaleMode)
End If
Label1(nCnt).Visible = True
Next
...

OBSERVARAS COMO SE GENERAN DE FORMA DINAMICA CINCO ETIQUETAS EN TIEMPO DE EJECUCION

UN SALUDO
Pablo Mereles21 de Septiembre del 2005
para saber el codigo para generar un label hace lo siguiente, abri un form que tenga un label con el block de notas y vas a ver el codigo de todos los objetos del form incluido el label.
¿Buscas más hilos como este? Mira el foro de Visual Basic o usa el buscador.