Public Class Form1
Dim NROWS As Integer = 5
Dim NCOLS As Integer = 3
Sub New()
' Chiamata richiesta dalla finestra di progettazione.
InitializeComponent()
For n = 0 To NCOLS - 1
For m = 0 To NROWS - 1
Dim casella As Label
casella = New Label
casella.Text = "ciccia"
Me.Controls.Add(casella)
casella.Left = n * casella.Width
casella.Top = m * casella.Height
casella.BorderStyle = BorderStyle.FixedSingle
casella.Visible = True
Next
Next
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Output:
Ma c'era un altro metodo che avevo usato in precedenza, che sistemava una griglia di caselle dato il numero delle caselle e il numero di caselle per riga.
Public Class Form1
Dim NLABELS As Integer = 15
Dim NCOLS As Integer = 3
Sub New()
' Chiamata richiesta dalla finestra di progettazione.
InitializeComponent()
For n = 0 To NLABELS - 1
Dim casella As Label
casella = New Label
casella.Text = "ciccia"
casella.Left = (n Mod NCOLS) * casella.Width
casella.Top = (n \ NCOLS) * casella.Height
Me.Controls.Add(casella)
casella.BorderStyle = BorderStyle.FixedSingle
casella.Visible = True
Next
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
...che dà un output simile, dato che il numero di caselle è divisibile per il numero di colonne...


Nessun commento:
Posta un commento