How to get Cursor position in the text of RichTextBox? 
Author Message
 How to get Cursor position in the text of RichTextBox?

Dear all,
    I am using C# to write a Editor. Could you please tell me how to
get the cursor position in the text of RichTextBox, so I can calculate
the text lines in row and column.

Thank you!
Jianren



Fri, 19 Nov 2004 14:57:39 GMT  
 How to get Cursor position in the text of RichTextBox?
Hi Jianren,

You can use the following method to get column/row number:

                int ColIndex;
                int RowIndex;
                int RowStartIndex;

                RowIndex=richTextBox1.GetLineFromCharIndex(richTextBox1.SelectionStart)+1;
                Console.WriteLine ("Row: " + RowIndex.ToString());

                richTextBox1.GetCharIndexFromPosition(richTextBox1.GetPositionFromCharIndex(richTextBox1.SelectionStart));  
                RowStartIndex =Win32.SendMessage(richTextBox1.Handle, Win32.EM_LINEINDEX, -1, 0);
                ColIndex=richTextBox1.SelectionStart-RowStartIndex+1;
                Console.WriteLine("Col:" + ColIndex.ToString());

Declare the SendMessage:

        public class Win32
        {
                public Win32()
                {
                        //
                        // TODO: Add constructor logic here
                        //
                }
                        [DllImport("User32.Dll")]
                public static extern int SendMessage(IntPtr hWnd,int Msg,int  wParam,int  lParam);                      
                public const int EM_LINEINDEX = 0xBB;
                  }

Hope this helps.

Regards,

Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.

Need quick answers to questions like these? The Microsoft Knowledge Base provides a wealth of information that you can use to troubleshoot a problem or answer a
question! It's located at http://support.microsoft.com/support/c.asp?M=F>.

--------------------

Quote:

>Newsgroups: microsoft.public.dotnet.languages.csharp
>Subject: How to get Cursor position in the text of RichTextBox?
>Date: 2 Jun 2002 23:57:39 -0700
>Organization: http://groups.google.com/
>Lines: 7

>NNTP-Posting-Host: 130.153.147.132
>Content-Type: text/plain; charset=ISO-8859-1
>Content-Transfer-Encoding: 8bit
>X-Trace: posting.google.com 1023087460 21984 127.0.0.1 (3 Jun 2002 06:57:40 GMT)

>NNTP-Posting-Date: 3 Jun 2002 06:57:40 GMT
>Path: cpmsftngxa07!tkmsftngxs02!tkmsftngp01!newsfeed00.sul.t-online.de!t-online.de!newsfeed.icl.net!isdnet!sn-xit-02!supernews.com!postnews1.google.com!not-for-
mail
>Xref: cpmsftngxa07 microsoft.public.dotnet.languages.csharp:65326
>X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

>Dear all,
>    I am using C# to write a Editor. Could you please tell me how to
>get the cursor position in the text of RichTextBox, so I can calculate
>the text lines in row and column.

>Thank you!
>Jianren



Sat, 20 Nov 2004 17:00:45 GMT  
 How to get Cursor position in the text of RichTextBox?
Dear Wu
Thank you for your kindly reply. It works fine.

Jianren

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sat, 20 Nov 2004 17:41:52 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Getting cursor position and text from OE compose window (Internet Explorer_Server)

2. wrong text position in RichTextBox

3. Q: Getting cursor position

4. rich text box cursor position?

5. how to set the position of the text-cursor ?!°

6. Determining cursor position in text box in C++ .NET

7. setting the position of the text cursor

8. How to put out some text at cursor position in any window

9. Getting the cursor back?!?!? (in text mode)

10. RichTextBox Scrollbar Position ?

11. RichTextBox Text Formating

12. How do I get and set the cursor position in a RichTextBox?

 

 
Powered by phpBB® Forum Software