?
Solved

Using Rich Edit in C#

Posted on 2004-04-30
5
Medium Priority
?
324 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 1500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

770 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