IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

ligne et colonnes d'une richtextbox


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Invité
    Invité(e)
    Par défaut ligne et colonnes d'une richtextbox
    bonjour a tousse

    j'ai voullu afficher le nombre de ligne et colonnes dans un label de ma richtextbox

    voici mon code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim m_lngTotalLigne As Long
            Dim m_lngNumLigne As Long
            Dim m_lngOldLigne As Long
            Dim iCount As Integer
            Dim iLastPos As Integer
     
            RichTextBoxFR1.Visible = True
            WebBrowser1.Visible = False
            ToolStripStatusLabel1.Text = DateTime.Now.ToLongDateString
            ToolStripStatusLabel5.Text = DateTime.Now.ToLongTimeString
            'nombre de caractères
            ToolStripStatusLabel2.Text = "lettres : " & _
             Len(Replace(Replace(Replace(RichTextBoxFR1.Text, vbCrLf, ""), _
             vbTab, ""), " ", ""))
     
            'nombre total de lignes
            m_lngTotalLigne = RichTextBoxFR1.GetLineFromCharIndex(Len(RichTextBoxFR1.Text)) + 1
     
            'ligne en cours
            m_lngNumLigne = RichTextBoxFR1.GetLineFromCharIndex(RichTextBoxFR1.SelectionStart) + 1
     
            'ligne en cours/nombre total de lignes
            ToolStripStatusLabel3.Text = "Lignes : " & m_lngNumLigne & _
            " / " & m_lngTotalLigne
            '----
            'affichage sur ligne 1
            If m_lngNumLigne = 1 Then
                iCount = RichTextBoxFR1.SelectionStart
            ElseIf m_lngNumLigne > 1 Then
                'récupère la position du curseur / la ligne en cours
                iLastPos = InStrRev(RichTextBoxFR1.Text, vbCrLf, RichTextBoxFR1.SelectionStart)
                iCount = RichTextBoxFR1.SelectionStart - iLastPos - 1
            End If
            '----
            m_lngOldLigne = m_lngNumLigne
            '----
            ToolStripStatusLabel4.Text = "Colonnes : " & iCount
        End Sub
    dans mes label il m'affiche nombre de ligne 0 et quand j'écrie il ne compte pas les lignes
    savez vous pourquoi ?
    bon j'avoue mon code n'est sans doute pas le plus jolie

  2. #2
    Invité
    Invité(e)
    Par défaut
    j'ai un peu changer mon code pour faire plus simple
    le voila
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
     Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            RichTextBoxFR1.Visible = True
            WebBrowser1.Visible = False
            ToolStripStatusLabel1.Text = DateTime.Now.ToLongDateString
            ToolStripStatusLabel5.Text = DateTime.Now.ToLongTimeString
     
            Dim i As Integer
     
            ToolStripStatusLabel2.ForeColor = Color.Blue
            i = RichTextBoxFR1.SelectionStart
            ToolStripStatusLabel2.Text = RichTextBoxFR1.GetLineFromCharIndex(i)
            ToolStripStatusLabel2.Text = RichTextBoxFR1.GetLineFromCharIndex(RichTextBoxFR1.SelectionStart) + 0
            i += 1
     
     
        End Sub
    mais sa ne marche toujours pas
    dans mon label il m'affiche 0 il ne compte pas les ligne
    savez vous pourquoi ?

  3. #3
    Membre Expert
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    700
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 700
    Par défaut
    Bonjour,
    il manque une boucle, genre do .... Loop While.
    Et le caractère de recherche genre VbCr

  4. #4
    Invité
    Invité(e)
    Par défaut
    je ne sait pas si mon code est bien clair
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
     
            Dim i As Integer
     
            ToolStripStatusLabel2.ForeColor = Color.Blue
     
            i = RichTextBoxFR1.SelectionStart
            ToolStripStatusLabel2.Text = RichTextBoxFR1.GetLineFromCharIndex(i)
            ToolStripStatusLabel2.Text = RichTextBoxFR1.GetLineFromCharIndex(Len(RichTextBoxFR1.Text)) + 0
            ToolStripStatusLabel2.Text = RichTextBoxFR1.GetLineFromCharIndex(RichTextBoxFR1.SelectionStart) + 0
            ToolStripStatusLabel2.Text = Len(Replace(RichTextBoxFR1.Text, vbCrLf, vbTab))
            i += 1
            i = InStrRev(RichTextBoxFR1.Text, vbCrLf, RichTextBoxFR1.SelectionStart)
     
     
        End Sub
    mais sa ne marche toujours pas mon label reste a zéro

  5. #5
    Membre Expert
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    700
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 700
    Par défaut
    bonsoir,
    je parlais de boucle, pour itérer et compter dans le texte, les retours chariot (vbCr).
    NB 1 : l'emploi de vbCrLf, selon la rédaction du texte, pourra indiquer la fin d'un chapitre ou la fin du texte lui même.
    NB 2 : Si le richtextbox est réduit sur sa largeur, une ligne réelle peut être présentée sur plusieurs lignes et la boucle ne peut en tenir compte.
    Voici un bout de code qui compte les lignes réelles et les présente dans TextBox1 :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
            Dim index As Integer = 0
     
            '*** Déclare une Arraylist qui comptabilise les numéros des lignes.
            '         (Les lignes vides sont également comptabilisées).
            Dim lineList As New System.Collections.ArrayList
            Do
                '*** Recherche les occurences de l'élément recherché et incrémente l'index de départ.
                '      Ici VbCr = Caractère de retour chariot
                index = RichTextBox1.Find(vbCr, index + 1, RichTextBoxFinds.None)
                If (index <> -1) Then
                    '*** recherche chaque ligne comportant l'élément cherché et ajoute son rang à la liste.
                    lineList.Add(RichTextBox1.GetLineFromCharIndex(index))
                End If
                '*** Si index = -1 : recherche infructueuse donc terminée.
            Loop While (index <> -1)
     
            TextBox1.Text = CStr(lineList.Count + 1) '+1 car l'index ArrayList commence à 0.
    Pour les colonnes dans un RichTextBox, je ne vois pas.

  6. #6
    Invité
    Invité(e)
    Par défaut
    il ne compte toujours pas les lignes avec se code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     Dim index As Integer = 0
            Dim lineList As New System.Collections.ArrayList
            Do
                index = RichTextBoxFR1.Find(vbCr, index + 1, RichTextBoxFinds.None)
                If (index <> -1) Then
                    lineList.Add(RichTextBoxFR1.GetLineFromCharIndex(index))
                End If
            Loop While (index <> -1)
     
            ToolStripStatusLabel2.Text = CStr(lineList.Count + 1)
    mème avec se code sa ne marche pas:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    Dim i As Integer
     
            ToolStripStatusLabel2.ForeColor = Color.Blue
     
            i = RichTextBoxFR1.SelectionStart
            ToolStripStatusLabel2.Text = RichTextBoxFR1.GetLineFromCharIndex(i)
            ToolStripStatusLabel2.Text = RichTextBoxFR1.GetLineFromCharIndex(Len(RichTextBoxFR1.Text)) + 0
            ToolStripStatusLabel2.Text = RichTextBoxFR1.GetLineFromCharIndex(RichTextBoxFR1.SelectionStart) + 0
            i += 1
            Dim index As Integer = 0
            Dim lineList As New System.Collections.ArrayList
            Do
                index = RichTextBoxFR1.Find(vbCr, index + 1, RichTextBoxFinds.None)
                If (index <> -1) Then
                    lineList.Add(RichTextBoxFR1.GetLineFromCharIndex(index))
                End If
            Loop While (index <> -1)
     
            ToolStripStatusLabel2.Text = CStr(lineList.Count + 1)

Discussions similaires

  1. [AC-2010] Lignes et colonnes dans une requête
    Par pascal5 dans le forum Requêtes et SQL.
    Réponses: 5
    Dernier message: 22/01/2013, 16h27
  2. Tri des lignes et colonnes d'une crosstab de Jasper
    Par flamant dans le forum Jasper
    Réponses: 1
    Dernier message: 02/02/2012, 16h25
  3. [WD15] ligne et colonne d'une table
    Par Theo.H dans le forum WinDev
    Réponses: 8
    Dernier message: 12/01/2012, 12h49
  4. [Débutant] conserver dans un vecter des indices de lignes et colonnes d'une matrice
    Par membreComplexe12 dans le forum MATLAB
    Réponses: 4
    Dernier message: 09/03/2010, 20h57
  5. Réponses: 9
    Dernier message: 19/12/2005, 15h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo