Private Sub FrmXProve2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Set property readonly=true, maxlenght=2, text="" and backcolor=white to all textboxes
'Obviously, it could be done also during the design operation
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox1.ReadOnly = True
TextBox2.ReadOnly = True
TextBox3.ReadOnly = True
TextBox4.ReadOnly = True
TextBox5.ReadOnly = True
TextBox6.ReadOnly = True
TextBox1.BackColor = System.Drawing.Color.White
TextBox2.BackColor = System.Drawing.Color.White
TextBox3.BackColor = System.Drawing.Color.White
TextBox4.BackColor = System.Drawing.Color.White
TextBox5.BackColor = System.Drawing.Color.White
TextBox6.BackColor = System.Drawing.Color.White
TextBox1.MaxLength = 2
TextBox2.MaxLength = 2
TextBox3.MaxLength = 2
TextBox4.MaxLength = 2
TextBox5.MaxLength = 2
TextBox6.MaxLength = 2
End Sub
Private Sub TestoVariato(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged, TextBox4.TextChanged, TextBox5.TextChanged, TextBox6.TextChanged
Static Done As Boolean = False
Static CursPos As Byte = 0
Dim Casella As TextBox = sender
If Done = False Then
If IsNumeric(Casella.Text) Then
If Byte.Parse(Casella.Text) > 49 Then
MsgBox("Max value permitted is 49")
Done = True
CursPos = Casella.SelectionStart
Casella.Undo()
Else
Casella.ClearUndo()
Done = False
End If
End If
Else
Casella.ClearUndo()
Done = False
Casella.SelectionStart = CursPos - 1
End If
sender.readonly = True
End Sub
Private Sub TextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress, TextBox2.KeyPress, TextBox3.KeyPress, TextBox4.KeyPress, TextBox5.KeyPress, TextBox6.KeyPress
Dim casella As TextBox = sender
Dim NewText As String
If Not (Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar) Or e.KeyChar.Equals(Keys.Delete)) Then
sender.ReadOnly = True
Exit Sub
Else
If casella.SelectionStart = 0 Then
NewText = e.KeyChar & casella.Text
If NewText.Length > 2 And Char.IsDigit(e.KeyChar) Then
e.Handled = True
Exit Sub
End If
Else
NewText = casella.Text & e.KeyChar
If NewText.Length > 2 And Char.IsDigit(e.KeyChar) Then
e.Handled = True
Exit Sub
End If
End If
If Not (NewText = TextBox1.Text Or NewText = TextBox2.Text Or NewText = TextBox3.Text Or NewText = TextBox4.Text Or NewText = TextBox5.Text Or NewText = TextBox6.Text) Then
sender.ReadOnly = False
Else
MsgBox(NewText & " is already digited! Choose another value")
End If
End If
End Sub
Private Sub TextBox_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave, TextBox2.Leave, TextBox3.Leave, TextBox4.Leave, TextBox5.Leave, TextBox6.Leave
sender.text = sender.Text.PadLeft(2, "0")
End Sub
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown, TextBox2.KeyDown, TextBox3.KeyDown, TextBox4.KeyDown, TextBox5.KeyDown, TextBox6.KeyDown
Dim Valore As Int16 = e.KeyValue
If (Valore = 46) Then
sender.ReadOnly = False
End If
End Sub