Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Application de formats dans une rich text box

2 réponses
Avatar
GnarlyYoyo
Bonjour,
J'ai écrit un code qui applique des formats de couleurs / gras dans une
rich text box. J'ai une fonction générique qui applique les formats, et une
autre qui définit les lois. L'objectif est d'appliquer des formats pour
mettre en évidence certaines lignes un peu comme dans un éditeur de code.
Le code marche bien, mais à l'exécution, je vois les lignes dans la rich
text box qui défilent. Comment faire pour ne plus avoir ce défilement?
Merci de votre aide!

Yoann


' ************************* ColorizeRTF *************************
' Input:
' r as RichTextBox: RichTextBox where the colorization laws are going to be
applied
'
' This procedure applies the colorization laws to a RichTextBox.

Sub ColorizeRTF(r As RichTextBox)
' Names of step are red
Call ColorizeItemRTF(r, "--Step", vbRed, True)
' Telecommands are blue
Call ColorizeItemRTF("ISSUE", vbBlue, False)
' Calls to procedures are orange
Call ColorizeItemRTF(r, "EXECUTE", RGB(255, 128, 0), False)
' Verifications are green
Call ColorizeItemRTF(r, "CHECK_ITEM", RGB(0, 128, 0), False)
' Beginning and end of FOR and REPEAT loops are bold
Call ColorizeItemRTF(r, "FOR I:=", vbBlack, True)
Call ColorizeItemRTF(r, "END FOR", vbBlack, True)
Call ColorizeItemRTF(r, "REPEAT", vbBlack, True)
Call ColorizeItemRTF(r, "UNTIL(", vbBlack, True)
' Place the selection point at the beginning of the code and clear any
selection
r.SelStart = 0
r.SelLength = 0
End Sub

' ************************* ColorizeItemRTF *************************
' Input:
' r As RichTextBox: RichTextBox where the colorization applies
' s as String: string to look for in the code. The entire line will then be
colorized.
' l as Long: color to be used
' IsBold as Boolean: if IsBold = TRUE, then the line turns bold
'
' This procedure applies a colorization law
' "If a line contains s, then the end of the line, starting at s, will get
the following settings:
' color is l
' if IsBold is TRUE, then it turns bold"


Sub ColorizeItemRTF(r As RichTextBox, s As String, l As Long, IsBold As
Boolean)
Dim index1 As Long, index2 As Long

Do
index1 = r.Find(s, index1 + 1, , modMain.rtfMatchCase Or
modMain.rtfNoHighlight)
If index1 = -1 Then Exit Do
index2 = r.Find(vbCrLf, index1, , modMain.rtfNoHighlight)
r.SelStart = index1
r.SelLength = index2 - index1 + 1
r.SelColor = l
r.SelBold = IsBold
Loop

End Sub

2 réponses

Avatar
Vincent Guichard
GnarlyYoyo a écrit :
Bonjour,
J'ai écrit un code qui applique des formats de couleurs / gras dans une
rich text box. J'ai une fonction générique qui applique les formats, et une
autre qui définit les lois. L'objectif est d'appliquer des formats pour
mettre en évidence certaines lignes un peu comme dans un éditeur de code.
Le code marche bien, mais à l'exécution, je vois les lignes dans la rich
text box qui défilent. Comment faire pour ne plus avoir ce défilement?
Merci de votre aide!

Yoann




Bonjour,

A priori, le problème viens des SelStart et autres qui forcent
l'affichage à se déplacer.

Tu peux peut-être cacher le contrôle le temps de faire les
modifications, ou faire celles-ci dans un second contrôle masqué et les
transposer ensuite dans le contrôle visible.

Vincent Guichard
Avatar
Driss HANIB
regarde l'API LockWindowUpdate avec comme paramètre le handle de ton rtf box
et qui bloquera l'affichage de celui-ci.
pour relacher l'affichage(après tes manips) il suffit de metre
lockwindowupdate (0)

Driss

"GnarlyYoyo" a écrit dans le message de
news:451a3e17$0$11368$
Bonjour,
J'ai écrit un code qui applique des formats de couleurs / gras dans une
rich text box. J'ai une fonction générique qui applique les formats, et


une
autre qui définit les lois. L'objectif est d'appliquer des formats pour
mettre en évidence certaines lignes un peu comme dans un éditeur de code.
Le code marche bien, mais à l'exécution, je vois les lignes dans la rich
text box qui défilent. Comment faire pour ne plus avoir ce défilement?
Merci de votre aide!

Yoann


' ************************* ColorizeRTF *************************
' Input:
' r as RichTextBox: RichTextBox where the colorization laws are going to


be
applied
'
' This procedure applies the colorization laws to a RichTextBox.

Sub ColorizeRTF(r As RichTextBox)
' Names of step are red
Call ColorizeItemRTF(r, "--Step", vbRed, True)
' Telecommands are blue
Call ColorizeItemRTF("ISSUE", vbBlue, False)
' Calls to procedures are orange
Call ColorizeItemRTF(r, "EXECUTE", RGB(255, 128, 0), False)
' Verifications are green
Call ColorizeItemRTF(r, "CHECK_ITEM", RGB(0, 128, 0), False)
' Beginning and end of FOR and REPEAT loops are bold
Call ColorizeItemRTF(r, "FOR I:=", vbBlack, True)
Call ColorizeItemRTF(r, "END FOR", vbBlack, True)
Call ColorizeItemRTF(r, "REPEAT", vbBlack, True)
Call ColorizeItemRTF(r, "UNTIL(", vbBlack, True)
' Place the selection point at the beginning of the code and clear any
selection
r.SelStart = 0
r.SelLength = 0
End Sub

' ************************* ColorizeItemRTF *************************
' Input:
' r As RichTextBox: RichTextBox where the colorization applies
' s as String: string to look for in the code. The entire line will then


be
colorized.
' l as Long: color to be used
' IsBold as Boolean: if IsBold = TRUE, then the line turns bold
'
' This procedure applies a colorization law
' "If a line contains s, then the end of the line, starting at s, will get
the following settings:
' color is l
' if IsBold is TRUE, then it turns bold"


Sub ColorizeItemRTF(r As RichTextBox, s As String, l As Long, IsBold As
Boolean)
Dim index1 As Long, index2 As Long

Do
index1 = r.Find(s, index1 + 1, , modMain.rtfMatchCase Or
modMain.rtfNoHighlight)
If index1 = -1 Then Exit Do
index2 = r.Find(vbCrLf, index1, , modMain.rtfNoHighlight)
r.SelStart = index1
r.SelLength = index2 - index1 + 1
r.SelColor = l
r.SelBold = IsBold
Loop

End Sub