Visual Basic.NET - Controles en ejecucion...

 
Vista:
sin imagen de perfil
Val: 17
Ha aumentado su posición en 8 puestos en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

Controles en ejecucion...

Publicado por CoquitoPe (19 intervenciones) el 27/04/2015 04:47:37
Un saludo ...
Por favor ayudenme en este código... porque sale error... o no se puede manejar matrices que crean controles en tiempo de ejecución...?
otra+ Al hacer click en un label creado (matLabel(intNum))... como lo identifico de los demás..?
Gracias...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
Private Sub NuevaForma()
 Dim intConColum, intConFila, intNum, intContad As Integer
 Dim sinAncho, sinAlto As Double
 Dim sinAcumAncho, sinAcumAlto As VariantType
 Dim strLeyenda, strFigura As String
 Dim intColum, intFilas, intFigura As Integer
 Do
 strLeyenda = "Numero de Figuras : "
 intFigura = InputBox(strLeyenda, "Formacion de Figuras", 3)
 strLeyenda = strLeyenda & intFigura & Chr(13) & Chr(10) & "Numero de Columnas : "
 intColum = InputBox(strLeyenda, "Formacion de Figuras", 6)
 strLeyenda = strLeyenda & intColum & Chr(13) & Chr(10) & "Numero de Filas.... : "
 intFilas = InputBox(strLeyenda, "Formacion de Figuras", 8)
 If (intColum * intFilas / intFigura) <> Int(intColum * intFilas / intFigura) Then _
 MsgBox(intColum & " x " & intFilas & " --> No es divisible para : " & intFigura & " figuras") : intColum = 0
 Loop While intColum < 3 Or intFigura < 2 Or intFilas < 3
 '----x-x-x-x-111
 Dim intNumero As Integer
 ReDim ramNumer(intColum * intFilas + 1)
 intContad = 0
 Dim ramNumDos As New Random
 Dim intMatriz As Integer
 For j As Integer = 1 To intColum
 For i As Integer = 1 To intFilas
 intContad = intContad + 1
 Do
 ramNumer(intContad) = ramNumDos.Next(1, intColum * intFilas + 1)
 For intMatriz = 1 To intContad - 1
 If ramNumer(intContad) = ramNumer(intMatriz) And intContad > 1 Then intMatriz = 0 : Exit For
 Next
 Loop While intMatriz = 0
 Next
 Console.Write("{0, 5}", ramNumer(intContad))
 Next
 ReDim matCarac(intColum * intFilas + 1)
 '----x-x-x-x- 2222
 intContad = 1
 strFigura = Chr(65)
 For j As Integer = 1 To intColum
 For i As Integer = 1 To intFilas
 matCarac(intContad) = strFigura
 If intContad > 0 And intContad Mod intFigura = 0 Then strFigura = Chr(65 + intContad / intFigura)
 intContad = intContad + 1
 Next
 Next
 Dim TablePanel As New TableLayoutPanel
 sinAncho = Int((1280 - intColum * 2) / intColum) : sinAlto = Int((760 - intFilas * 2) / intFilas)
 TablePanel.ColumnCount = intColum
 TablePanel.Dock = DockStyle.None
 TablePanel.RowCount = intFilas
 TablePanel.Width = 1280 : TablePanel.Height = 760
 TablePanel.Left = 0 : TablePanel.Top = 0
 TablePanel.BackColor = Color.Beige
 TablePanel.AllowDrop = False
 TablePanel.AutoScroll = False
 TablePanel.ImeMode = Windows.Forms.ImeMode.NoControl
 TablePanel.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowOnly
 TablePanel.CellBorderStyle = TableLayoutPanelCellBorderStyle.InsetDouble
 Dim mLbl(intColum * intFilas) As Label
 intNum = 0 : sinAcumAncho = 0 : sinAcumAlto = 0 : strFigura = Chr(65) '"A"
 ReDim matLabel(intColum * intFilas)
 For j As Integer = 1 To intColum
 For i As Integer = 1 To intFilas
 intNum = intNum + 1
 Dim matLabel(intNum) As Label
stop
'----  Desde aquí la falla
 matLabel(intNum).Text = matCarac(ramNumer(intNum))
 matLabel(intNum).TextAlign = ContentAlignment.MiddleCenter
 matLabel(intNum).Font = New System.Drawing.Font("Webdings", 45)
 matLabel(intNumero).Dock = DockStyle.Fill
 'matLabel(intnumero).AutoSize = True
 matLabel(intNumero).Size = New System.Drawing.Size(sinAncho, sinAlto)
 matLabel(intNumero).Location = New System.Drawing.Point(sinAcumAncho, sinAcumAlto)
 sinAcumAncho = sinAcumAncho + sinAncho + 1 : sinAcumAlto = sinAcumAlto + sinAlto + 1
 matLabel(intNumero).BackColor = Color.Blue
 TablePanel.Controls.Add(matLabel(intNumero), j - 1, i - 1)
 Next
 Next
 Me.Controls.Add(TablePanel)
 Exit Sub
 End Sub
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
Val: 481
Bronce
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

Controles en ejecucion...

Publicado por Miguel (476 intervenciones) el 27/04/2015 05:12:22
Hola, creo que sería más sencillo si dentro de los dos bucles ("j" e "i") crearas y agregaras al contenedor uno por uno de los controles (label´s) . Ejemplo:

1
2
3
4
5
6
7
8
9
10
For j As Integer = 1 To intColum
     For i As Integer = 1 To intFilas
          intNum = intNum + 1
          Dim tuLabel As New Label
          tuLabel.Text= ""
          'Etc...
          TablePanel.Controls.Add(tuLabel, j - 1, i - 1)
      Next
Next
Me.Controls.Add(TablePanel)


Con lo segundo, si le asignas un valor a la propiedad "Tag" lo podrás identificar, o por el valor de alguna de sus propiedades.


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