Visual Basic.NET - Label dinamico

 
Vista:

Label dinamico

Publicado por Pedrolidas (2 intervenciones) el 13/12/2007 13:10:30
Hola a todos, tengo un problemilla con vb net, pues estoy haciendo un programilla en el cual voy guardando en un arrays lo que voy recogiendo por inputbox, pues mi intencion es ir creando labels
con las palabras que guardo en el arrays, uno debajo de otro. No se si me entendeis, aki les dejo mi codigo a ver si me podeis dar alguna solucion. GRACIAS

Public Class Form1

Dim lb As Label = New Label
'Dim lb2 As Label = New Label
Dim jugadores() As String
Dim pos As Point

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Njugadores As Integer

Dim i As Integer

pos.X = Label1.Location.X
pos.Y = Label1.Location.Y + 5
'Label1 es un label que he puesto en el form de referencia

Njugadores = InputBox("INTRODUCE EL NUMERO DE JUGADORES")

jugadores = New String(Njugadores) {}

For i = 0 To Njugadores - 1
jugadores(i) = InputBox("Introduce el nombre del jugador " & i + 1)
Next

For i = 0 To Njugadores - 1
labeldinamico(i)
Next

End Sub
Private Sub labeldinamico(ByVal i As Integer)
Dim lb2 = New Label

lb2.Location = pos
lb2.Text = jugadores(i)
Me.Controls.Add(lb2)

'pos.Y = lb2.Location.Y + 10
End Sub
End Class
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

RE:Label dinamico

Publicado por P. J. (706 intervenciones) el 13/12/2007 16:44:54
Aqui te dejo el codigo, con las correcciones para que funcione XD

Public Class Arreglos

Dim strJugadores() As String
Dim intTop As Integer = 20
Dim oLabel() As Label

Private Sub labelDinamico(ByVal intIndice As Integer)
oLabel(intIndice) = New Label 'AQUI INSTANCIO POR EL INDICE
oLabel(intIndice).Location = New Point(10, intTop)
oLabel(intIndice).Text = strJugadores(intIndice)
Me.Controls.Add(oLabel(intIndice))
intTop = oLabel(intIndice).Location.X + 30
AddHandler oLabel(intIndice).Click, AddressOf Evento 'ESTO LO PUEDES QUITAR, PERO ASI SE AGREGA EL EVENTO
End Sub

Private Sub Arreglos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim intTotal As Integer
intTotal = InputBox("INTRODUCE EL NUMERO DE JUGADORES")
strJugadores = New String(intTotal) {}
oLabel = New Label(intTotal) {} 'AQUI INSTANCIO EL TOTAL DE LABEL QUE HABRAN

For i As Integer = 0 To intTotal - 1
strJugadores(i) = InputBox("Introduce el nombre del jugador " & i + 1)
Next
For j As Integer = 0 To intTotal - 1
labelDinamico(j)
Next
End Sub

'ESTE ES EL EVENTO CLICK PARA TU CONTROL
Private Sub Evento(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox("Haz hecho click en el Boton: " & sender.ToString, MsgBoxStyle.Information)
End Sub

End Class

Agregue la parte del Evento por si lo necesitas luego sino quitalo nomas.
Salu2.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Label dinamico

Publicado por pedrolidas (2 intervenciones) el 14/12/2007 10:59:09
Muchas gracias tio, me has servido de gran ayuda porque estaba ya por dejarlo.
Muchos saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar