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();
精彩评论