Solved

Using Rich Edit in C#

Posted on 2004-04-30
5
285 Views
Last Modified: 2013-11-13
When I use the Rich Text Box in C#, how can I determine the character index that represents the first characterat the beginning of any given line of text in the editor.  Cannot rely on mouse and cannot afford to dump all of the editor lines into an array of strings.
0
Comment
Question by:terider
  • 2
  • 2
5 Comments
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10965471
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 10966054
Assuming that form has richTextBox1 control, this code shows message with each line start index and first character in it. You can continue from this point adding your own functionality:

using System.Text.RegularExpressions;
using System.Text;


        private void button1_Click(object sender, System.EventArgs e)
        {
            Regex r;
            StringBuilder sb = new StringBuilder();
            int nLen = richTextBox1.Text.Length;

            r = new Regex("[\n]");

            MatchCollection mc = r.Matches(richTextBox1.Text, 0);

            if ( nLen > 0 )
            {
                sb.AppendFormat("{0} {1}\n", 0,
                    richTextBox1.Text[0].ToString());

                foreach (Match m in mc)
                {
                    if ( m.Index < richTextBox1.Text.Length - 1 )
                    {
                        sb.AppendFormat("{0} {1}\n", m.Index + 1,
                            richTextBox1.Text[m.Index + 1].ToString());
                    }
                }
            }

            MessageBox.Show(this, sb.ToString());
        }
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 11151903
Usually I don't have anything against splitting points, but this time I want to see .NET area page editor opinion how rama_krishna580's links are related to this question. He is known in .NET and C# areas as expert sending a lot of links found in Google. In this case I guess these links are first four results of Google "Rich Text Box C#" search.
0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 11162148
Hi AlexFM,

I strongly disagree with your statements above, i agree that i give links for the problems, but in this case did you read my links properly, how can you say that my links are not related to this question...look at this link...
don;t you see how to solve this above problem using my links, which shows alternative ways of deal this type of problems.....any way since page editor decided , i don;t want to say anything against his/her decision, but i want to tell you some thing , read the documents first before you do any comments on other peoples answers. Here lot of experts are providing solutions in different ways. My way of approach is providing links , your way may be different...so i suggest you not to make these kind of comments on other peoples answers.
Anyway Congrats for getting Points.....!

Best of luck..

R.K
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question