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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| Imports System.Threading
Public Class Form1
'RichTextBox2.text est le texte destination en cours d'écriture
Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.ActiveControl = Nothing 'aucun control a le focus
RichTextBox1.Font = New Font("ARIAL", 26, FontStyle.Regular)
RichTextBox1.Width = 444
RichTextBox1.Height = 56
RichTextBox2.Font = New Font("ARIAL", 16, FontStyle.Regular)
Thread.Sleep(100)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
RichTextBox1.Text = ""
'lit 8 caractères hexadécimal du tableau unicode
For n = &H2660 To &H266F
RichTextBox1.Text += ChrW(n)
Next n
End Sub
Public Sub RichTextBox1_MousemMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles RichTextBox1.MouseMove
Dim gdi As Graphics = RichTextBox1.CreateGraphics()
Dim box = DirectCast(sender, RichTextBox)
Dim index = box.GetCharIndexFromPosition(e.Location)
'efface tous les rectangles rouge
For n = 0 To 7
Dim WhitePen As New Pen(Color.White, 3)
Dim rectVide As New Rectangle(1 + n * 24, 0, 24, 52)
gdi.DrawRectangle(WhitePen, rectVide)
Next n
'affiche un rectangle rouge
Dim RedPen As New Pen(Color.Red, 3)
Dim rect As New Rectangle(1 + index * 24, 0, 24, 52)
gdi.DrawRectangle(RedPen, rect)
''tempo pour limiter le scintillement lorsque mous move sur le caractère
Thread.Sleep(20)
End Sub
Public Sub RichTextBox1_MouseLeave(sender As Object, e As MouseEventArgs)
Dim gdi As Graphics = RichTextBox1.CreateGraphics()
Dim box = DirectCast(sender, RichTextBox)
Dim index = box.GetCharIndexFromPosition(e.Location)
'efface un rectangle rouge
Dim RedPen As New Pen(Color.White, 3)
Dim rect As New Rectangle(1 + index * 24, 0, 24, 52)
gdi.DrawRectangle(RedPen, rect)
End Sub
Private Sub RichTextBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles RichTextBox1.MouseDown
Dim gdi As Graphics = RichTextBox1.CreateGraphics()
'efface tous les rectangles rouge
For n = 0 To 7
Dim WhitePen As New Pen(Color.White, 3)
Dim rectVide As New Rectangle(1 + n * 24, 0, 24, 52)
gdi.DrawRectangle(WhitePen, rectVide)
Next n
'Recherche position de la souris
Dim box = DirectCast(sender, RichTextBox)
Dim index = box.GetCharIndexFromPosition(e.Location)
'sélectionne le caractère qui reçoit le click
Dim SelectCharacter = box.GetCharFromPosition(e.Location)
Dim SelectPosition = box.GetPositionFromCharIndex(index)
'place le curseur en fin de ligne de texte
RichTextBox1.SelectionStart = RichTextBox1.TextLength
RichTextBox2.Focus()
'Ajoute le caractères au RichTextBox2
RichTextBox2.Text += SelectCharacter
End Sub
Private Sub RichTextBox2_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles RichTextBox2.KeyDown
'place le curseur à la fin de la ligne de texte
RichTextBox2.SelectionStart = RichTextBox2.TextLength
End Sub
End Class |
Partager