[RichTextBox]Recuperation de la ligne et de la colonne en cours

Résolu
cs_ip2x Messages postés 63 Date d'inscription mercredi 9 février 2005 Statut Membre Dernière intervention 27 janvier 2009 - 8 nov. 2006 à 10:58
cs_ip2x Messages postés 63 Date d'inscription mercredi 9 février 2005 Statut Membre Dernière intervention 27 janvier 2009 - 9 nov. 2006 à 00:33
Bonjour,

je developpe un "parser" XML a l'aide d'une RichTextBox et je voudrais, pour des soucis d'ergonomie, afficher la position du curseur (Ligne, Colonne) dans la barre d'etat de mon formulaire...

Quelqu'un aurait-il un algo qui traine

2 réponses

cs_Bidou Messages postés 5487 Date d'inscription dimanche 4 août 2002 Statut Membre Dernière intervention 20 juin 2013 61
8 nov. 2006 à 15:06
Salut,
La richtextbox met des méthodes à disposition qui devrait t'aider. Jette un oeil du côté de

GetCharIndexFromPosition();
GetFirstCharIndexOfCurrentLine();

<hr size="2" />-Blog-
3
cs_ip2x Messages postés 63 Date d'inscription mercredi 9 février 2005 Statut Membre Dernière intervention 27 janvier 2009
9 nov. 2006 à 00:33
Oui aprés un aprés-midi acharnée j'ai trouvé cette solution :
private void mettreAJourStatusBar()
        {
            //Recuperation de l'index du curseur dans tout le document
            int position = this.richTextBoxAfficherXML.SelectionStart;
            
            //Initialisation de la valeur de la colonne
            int col = 0;

            //Recuperation de la ligne a laquelle le curseur se trouve
            //a partir de l'index de celui-ci
            int lin = this.richTextBoxAfficherXML.GetLineFromCharIndex(position) +1; 
            
            try
            {   
                col = position -this.richTextBoxAfficherXML.Text.LastIndexOf(System.Convert.ToChar(10), position - 1) - 1;
            }
            catch
            {
                col +=1;
            }

            //Affichage final
            this.toolStripStatusLabelNbChar.Text    = "| nbchar " + this.richTextBoxAfficherXML.Text.Length.ToString();
            this.toolStripStatusLabelLIGNES.Text    = "| Ln " + lin;
            this.toolStripStatusLabelCOLONNES.Text  = "Col " + col;
            this.toolStripStatusLabelSELECTED.Text  = "| Sel " + this.richTextBoxAfficherXML.SelectedText.Length;
        }


J'espere que ça aidera quelqu'un
3
Rejoignez-nous