Solved

Using Rich Edit in C#

Posted on 2004-04-30
5
262 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
A short article about problems I had with the new location API and permissions in Marshmallow
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now