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
| Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'abonnements à l'évènement TextBox.KeyDown
AddHandler TextBox1.KeyDown, AddressOf TextBox_KeyDown
AddHandler TextBox2.KeyDown, AddressOf TextBox_KeyDown
'abonnement à l'évènement TextBox.MouseClick
AddHandler TextBox1.MouseClick, AddressOf TextBox_MouseClick
End Sub
Private Sub TextBox_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs)
Dim tb As TextBox = sender
If tb Is TextBox1 Then '<- si la TextBox EST la TextBox1
Lol(tb) '<- on passe en paramètre la TextBox en question
ElseIf tb Is TextBox2 Then '<- si la TextBox EST la TextBox1
Bonjour(tb) '<- on passe en paramètre la TextBox en question
End If
e.SuppressKeyPress = True '<- on évite la frappe en cours
End Sub
Private Sub TextBox_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim tb As TextBox = sender
tb.Clear()
End Sub
Private Sub Lol(ByVal tb As TextBox)
'on écrit le texte dans la TextBox passée en paramètre
'ici on ne sait pas si c'est TextBox1 ou TextBox2
tb.Text = "lol"
End Sub
Private Sub Bonjour(ByVal tb As TextBox)
'on écrit le texte dans la TextBox passée en paramètre
'ici on ne sait pas si c'est TextBox1 ou TextBox2
tb.Text = "bonjour"
End Sub
End Class |