Solved

Using Rich Edit in C#

Posted on 2004-04-30
5
274 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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to split this in C++ 4 94
parentbit challenge 3 77
Installed softare without GUID 6 66
Is doing tutor.com teaching in my situation advisable? 2 58
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…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

863 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

24 Experts available now in Live!

Get 1:1 Help Now