allthew3
Messages postés551Date d'inscriptionsamedi 8 janvier 2005StatutMembreDernière intervention12 avril 2008
-
5 mars 2007 à 17:56
allthew3
Messages postés551Date d'inscriptionsamedi 8 janvier 2005StatutMembreDernière intervention12 avril 2008
-
14 mars 2007 à 11:12
Bonjour,
Est-ce que quelqu'un serait s'il est possible, en Visual Basic .NET 2005 (donc FrameWork 2), de colorer un mot précis dans un contrôle RichTextBox ...
Si non, comment contourner, quoi d'autre utilisé ?
cs_casy
Messages postés7741Date d'inscriptionmercredi 1 septembre 2004StatutMembreDernière intervention24 septembre 201440 5 mars 2007 à 18:48
.SelectionColor modifie la couleur du texte sélectionné.
Reste à toi de sélectionner ce texte, tu as effectivement plusieurs pistes possibles. Regarde aussi surtout la methode .Select de la classe RichTextBox
---- Sevyc64 (alias Casy) ---- # LE PARTAGE EST NOTRE FORCE #
cs_casy
Messages postés7741Date d'inscriptionmercredi 1 septembre 2004StatutMembreDernière intervention24 septembre 201440 5 mars 2007 à 21:49
tiens regarde ce code, je l'ai un peu corriger
Dim keyword As String() = {"echo", "shuffle", "php"}
Private Sub RichTextBox1_TextChanged(ByVal
sender As System.Object, ByVal e As System.EventArgs) Handles
RichTextBox1.TextChanged
Dim line As String = ""
'Sauvegarde de la
couleur et de la position actuelle
Dim defColor As Color = RichTextBox1.SelectionColor
Dim defPos As Integer = RichTextBox1.SelectionStart
Try
With RichTextBox1
For i As Integer = 0 To .Lines.GetUpperBound(0)
line = .Lines.GetValue(i).ToString
If String.IsNullOrEmpty(line) Then
Exit Try
line = line.ToLowerInvariant
For j As Integer = 0 To keyword.GetUpperBound(0)
If line.Contains(keyword(j))
Then
.SelectionStart = line.IndexOf(keyword(j)) +
.GetFirstCharIndexFromLine(i)
.SelectionLength =
keyword(j).Length
.SelectionColor =
Color.Blue
End If
Next
Next
End With
Catch ex As Exception
Exit Try
Finally
'
Systématiquement, on restaure la position du curseur et la couleur par
défaut
RichTextBox1.SelectionStart
= defPos
RichTextBox1.SelectionLength = 0
RichTextBox1.SelectionColor = defColor
End Try
End Sub
---- Sevyc64 (alias Casy) ---- # LE PARTAGE EST NOTRE FORCE #
allthew3
Messages postés551Date d'inscriptionsamedi 8 janvier 2005StatutMembreDernière intervention12 avril 20082 5 mars 2007 à 19:20
Voici ce que j'ai écris mais c'est encore plus compliqué que je le pensais :-(
si tu pouvais m'aider ... c'est pourtant simple (dans la tete en tout cas) mais pour codé ça ... wow!
Dim
keyword
As
Object
() = {
"echo"
,
"shuffle"
,
"php"
}
Private
Sub
RichTextBox1_TextChanged(
ByVal
sender
As
System.Object,
ByVal
e
As
System.EventArgs)
Handles
RichTextBox1.TextChanged
Try
With
RichTextBox1
Dim
line
As
String
=
""
For
i
As
Integer
= 0
To
.Lines.GetUpperBound(0)line = .Lines.GetValue(i).ToString