?
Solved

Using Rich Edit in C#

Posted on 2004-04-30
5
Medium Priority
?
337 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
4 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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 …
Loops Section Overview

850 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