Ajouter ligne formatée dans RichEditBox

Résolu
BiGOuF Messages postés 90 Date d'inscription vendredi 13 décembre 2002 Statut Membre Dernière intervention 12 décembre 2007 - 7 nov. 2006 à 02:28
BiGOuF Messages postés 90 Date d'inscription vendredi 13 décembre 2002 Statut Membre Dernière intervention 12 décembre 2007 - 7 nov. 2006 à 15:04
Bonjour à tous,

je suis débutant en vb, et celà fait quelques jours que je cherche des tutos sur les RichEditBox pour VB6.

Je suis en train de faire un convertisseur de texte pour que celui-ci possède des tags pour forum phpBB.
J'arrive sans problème à generer le BBcode, mais je n'arrive pas à afficher un apperçu dans une RichEditBox.
Quand je tente un RichEditBox1.TextRTF = RichEditBox1.TextRTF & chr(13) & "Nouveau texte formaté", celui-ci ne s'ajoute pas.
J'ai toujours la première ligne dans la REB, mais pas la suite ... pourriez-vous m'aider ?
Merci d 'avance à tous :)

9 réponses

PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
7 nov. 2006 à 14:37
umm....

et comme çà?

Option Explicit
'
Const RTB_JAUNE     As String =  "\red255\green255\blue0"
Const RTB_ROUGE     As String = "\red255\green0\blue0"
Const RTB_BLEU      As String = "\red0\green0\blue255"
Const RTB_VERT      As String = "\red0\green255\blue0"
Const RTB_VIOLET    As String = "\red255\green0\blue255"
'
Private Sub Form_Load()
'  
clear
    RichTextBox1.Text = vbNullString
    
    Call AddRichLine(RTB_JAUNE & ";" & RTB_VERT & ";" & RTB_BLEU, "Ce qui suit est en \cf1 \i Vert Italique \f0 \cf0
\i0")
    Call AddRichLine(RTB_JAUNE & ";" & RTB_VERT & ";" & RTB_BLEU, "\cf2Ma Nouvelle Ligne")
End Sub
'
Sub AddRichLine(sColor As String, sLine As String)
    RichTextBox1.SelStart = Len(RichTextBox1.Text)
    If LenB(RichTextBox1.Text) > 0 Then
        RichTextBox1.SelText = vbCrLf
        RichTextBox1.SelStart = Len(RichTextBox1.Text)
    End If
    RichTextBox1.SelRTF = "{\rtf1\ansi {
\colortbl" & sColor & sLine & ";}" & sLine & "}"
End Sub

<small>Coloration
syntaxique automatique [AFCK] </small>
       

<hr size ="2" width="100%" />Prenez un instant pour répondre à ce sondage svp
3
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
7 nov. 2006 à 11:03
salut
    RichEditBox1.SelStart = Len(RichEditBox1.Text)
    RichEditBox1.SelText = VbCrLf & MaNouvelleLigne

çà donne quoi?
++
<hr size="2" width="100%" />Prenez un instant pour répondre à ce sondage svp
0
BiGOuF Messages postés 90 Date d'inscription vendredi 13 décembre 2002 Statut Membre Dernière intervention 12 décembre 2007
7 nov. 2006 à 12:49
Là, ca marche ;)
Alors, si je veux que toutes mes lignes soient affichées dés le début, je dois mettre quoi dans le form.load ?

RichEditBox1.SelStart = Len(RichEditBox1.Text)
RichEditBox1.SelText = VbCrLf & MaNouvelleLigne1
RichEditBox1.SelStart = Len(RichEditBox1.Text)
RichEditBox1.SelText = VbCrLf & MaNouvelleLigne2
RichEditBox1.SelStart = Len(RichEditBox1.Text)
RichEditBox1.SelText = VbCrLf & MaNouvelleLigne3
...

Ainsi de suite ?
En tout cas, merci d'avance :)
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
7 nov. 2006 à 12:59
presque...
les procédures sont là pour çà....

Call AddRichLine(MaNouvelleLigne1)
Call AddRichLine(MaNouvelleLigne2)
Call AddRichLine(MaNouvelleLigne3)

Sub AddRichLine(sLine As String)
    RichEditBox1.SelStart =  Len(RichEditBox1.Text)
    RichEditBox1.SelText = vbCrLf & sLine
End Sub

<small>Coloration
syntaxique automatique [AFCK] </small>
       

++
PCPT   [AFCK]
<hr size ="2" width="100%" />Prenez un instant pour répondre à ce sondage svp
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
BiGOuF Messages postés 90 Date d'inscription vendredi 13 décembre 2002 Statut Membre Dernière intervention 12 décembre 2007
7 nov. 2006 à 13:40
J'ai un petit problème qui subsiste.

Private Sub Form_Load()




'Declaration couleurs

Dim jaune


As String
Dim rouge



As String





Dim


bleu


As String





Dim


vert


As String





Dim


violet


As String







'fin declaration couleur





jaune = "\red255\green255\blue0"
rouge = "\red255\green0\blue0"
bleu = "\red0\green0\blue255"
vert = "\red0\green255\blue0"
violet = "\red255\green0\blue255"



RichTextBox1.TextRTF = "{\rtf1\ansi { \colortbl" & jaune & ";" & vert & ";" & bleu & ";}Ce qui suit est en \cf1 \i Vert Italique \f0 \cf0 \i0 }"
    RichTextBox1.SelStart = Len(RichTextBox1.Text)
    RichTextBox1.SelText = vbCrLf & "{\rtf1\ansi { \colortbl" & jaune & ";" & vert & ";" & bleu & ";} \cf2MaNouvelleLigne}"



End Sub




Etant donné que j'utilise .SelText, il formatte pas la suite => mon résultat est celui-ci :




         Ce qui suit est en



Vert Italique 
         {\rtf1\ansi { \colortbl\red255\green255\blue0;\red0\green255\blue0;\red0\green0\blue255;} \cf2MaNouvelleLigne}





Maintenant, si je remplace dans ce même code le .SelText par .SelRTF, j'ai ceci :




         Ce qui suit est en



Vert Italique


MaNouvelleLigne


Il faudrait que je trouve une alternative à :

RichTextBox1.TextRTF = "{\rtf1\ansi { \colortbl" & jaune & ";" & vert & ";" & bleu & ";}Ce qui suit est en \cf1 \i Vert Italique \f0 \cf0 \i0 }"
RichTextBox1.SelStart = Len(RichTextBox1.Text)
RichTextBox1.SelText = vbCrLf
RichTextBox1.SelStart = Len(RichTextBox1.Text)
RichTextBox1.SelRTF = vbCrLf & "{\rtf1\ansi { \colortbl" & jaune & ";" & vert & ";" & bleu & ";} \cf2MaNouvelleLigne}"

Celà dit, celà ne me pose pas un gros problème, mais si vous connaissez une version plus ... light :)

En tout cas, je vous remercie tous pour votre rapidité et votre efficacité :)
0
BiGOuF Messages postés 90 Date d'inscription vendredi 13 décembre 2002 Statut Membre Dernière intervention 12 décembre 2007
7 nov. 2006 à 14:38
A dire vrai, ca n'allège pas le code plus que le mien, mais merci beaucoup en tout cas, et j'espère que ca pourra aider d'autres neophytes comme moi :)

Bien à vous
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
7 nov. 2006 à 14:39
WOUPS....

RichTextBox1.SelRTF = "{\rtf1\ansi { \colortbl" & sColor & ";}" & sLine & "}"

<hr size="2" width="100%" />Prenez un instant pour répondre à ce sondage svp
0
BiGOuF Messages postés 90 Date d'inscription vendredi 13 décembre 2002 Statut Membre Dernière intervention 12 décembre 2007
7 nov. 2006 à 15:01
Je viens de tester ceci, et ca me fonctionne pas, ma RichBox est vide, le curseur est à la 3eme ligne, mais le dessus est vierge :

Option Explicit
'
Const RTB_JAUNE     As String = "\red255\green255\blue0"
Const RTB_ROUGE     As String = "\red255\green0\blue0"
Const RTB_BLEU      As String = "\red0\green0\blue255"
Const RTB_VERT      As String = "\red0\green255\blue0"
Const RTB_VIOLET    As String = "\red255\green0\blue255"
'
Private Sub Form_Load()
'   clear
    RichTextBox2.Text = vbNullString
   
    Call AddRichLine(RTB_JAUNE & ";" & RTB_VERT & ";" & RTB_BLEU, "Ce qui suit est en \cf1 \i Vert Italique \f0 \cf0 \i0")
    Call AddRichLine(RTB_JAUNE & ";" & RTB_VERT & ";" & RTB_BLEU, "\cf2Ma Nouvelle Ligne")
End Sub
'
Sub AddRichLine(sColor As String, sLine As String)
    RichTextBox1.SelStart = Len(RichTextBox1.Text)
    If LenB(RichTextBox1.Text) > 0 Then
        RichTextBox2.SelText = vbCrLf
        RichTextBox2.SelStart = Len(RichTextBox1.Text)
    End If
    RichTextBox1.SelRTF = "{\rtf1\ansi { \colortbl" & sColor & ";}" & sLine & "}"
End Sub
0
BiGOuF Messages postés 90 Date d'inscription vendredi 13 décembre 2002 Statut Membre Dernière intervention 12 décembre 2007
7 nov. 2006 à 15:04
Oups, au temps pour moi ... j'avais mal défini les names ... Ca fonctionne, un grand merci, et désolé encore :)
0
Rejoignez-nous