简体   繁体   中英

how to display the cursor's position in a richtextbox in C#

Im looking for a quick solution for this problem I have. In my app I have a richtextbox, I want to make a code that will capture the current position of the cursor and display it on the richtextbox as a mouse coordinate. the cursor's position is screen wise and not just focused on the app itself. All help will be widely appreciated.

TextBoxBase.SelectionStart and TextBoxBase.SelectionLength can be used . See the examples also.

You may want to check C# Windows Forms RichTextBox cursor position also .

I'm not sure if you really mean "cursor" or if you mean mouse pointer. Both terms are used to refer to the mouse pointer, but of course "cursor" used to just mean the little flashy thing that tells you where you're typing.

If you want the screen coordinates of the mouse pointer, use the static Position property of the Cursor (see what I mean?) class:

richTextBox.Text = Cursor.Position.ToString();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM