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
|
Public Class Form2
Private tbsw As New TextBoxSwitchWorker
Public Sub New()
' Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
tbsw.Add(Me.TextBox1)
tbsw.Add(Me.TextBox2)
tbsw.Add(Me.TextBox3)
tbsw.Add(Me.TextBox4)
End Sub
End Class
Public Class TextBoxSwitchWorker
Inherits Hashtable
Private currentIndex As Integer
Public Overloads Sub Add(ByVal t As TextBox)
MyBase.Add(t, False)
AddHandler t.Click, AddressOf EvaluateSwitch
End Sub
Public Overloads Sub Remove(ByVal t As TextBox)
RemoveHandler t.Click, AddressOf EvaluateSwitch
MyBase.Remove(t)
End Sub
Private Sub EvaluateSwitch(ByVal sender As Object, ByVal e As EventArgs)
Dim tb As TextBox = CType(sender, TextBox)
' C'est le textbox déja clické, on désactive
If Me(tb) Then
tb.BackColor = Color.White
Me(tb) = False
Exit Sub
End If
' Le textbox n'est pas celui sélectionné --> on switch
' si l'un des textbox est déjà clické
For Each temptb As TextBox In Me.Keys
If Me(temptb) Then
temptb.BackColor = Color.White
Me(temptb) = False
Dim strText As String = tb.Text
tb.Text = temptb.Text
temptb.Text = strText
Exit Sub
End If
Next
' sinon on positionne le top clické
Me(tb) = True
tb.BackColor = Color.Green
End Sub
End Class |
Partager