Ecco il codice della libreria di classi:
Imports System.Windows.Forms Public Class Griglia(Of T As {New, Control}) Sub New(ByRef myForm As Form, ByVal numCaselle As Integer, ByVal rowLength As Integer, ByVal Orientamento As Integer) For n As Integer = 0 To (numCaselle - 1) Dim casella As T = New T If Orientamento = GRIGLIA_ORIZZONTALE Then casella.Left = casella.Width * (n Mod rowLength) casella.Top = casella.Height * (n \ rowLength) ElseIf Orientamento = GRIGLIA_VERTICALE Then casella.Top = casella.Height * (n Mod rowLength) casella.Left = casella.Width * (n \ rowLength) End If myForm.Controls.Add(casella) Next End Sub End Class Public Module Costanti Public Const GRIGLIA_ORIZZONTALE As Integer = 1 Public Const GRIGLIA_VERTICALE As Integer = 0 End Moduleed ecco il codice dell'applicazione che usa la classe Griglia (che è tornata unica):
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim miaGriglia As New Griglia(Of GTextBox)(Me, 46, 5, GRIGLIA_VERTICALE) End Sub End Class Class GTextBox Inherits TextBox Sub New() Multiline = True Height = 50 Width = 50 End Sub End ClassIn tal modo basta inserire una costante come parametro, e a seconda della costante inserita la griglia avrà un orientamento orizzontale o verticale.
Senza tante chiacchiere!
Nessun commento:
Posta un commento