如何在C#中的richtextbox中显示光标的位置
我正在寻找针对这个问题的快速解决方案。在我的应用程序中,我有一个 RichTextBox,我想编写一个代码来捕获光标的当前位置并将其显示在 RichTextBox 上作为鼠标坐标。光标的位置是屏幕上的,而不仅仅是集中在应用程序本身。所有帮助都将受到广泛赞赏。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TextBoxBase.SelectionStart 和 TextBoxBase.SelectionLength 可以使用。
另请参阅示例。
您可能还需要检查 C# Windows 窗体 RichTextBox 光标位置。
TextBoxBase.SelectionStart and TextBoxBase.SelectionLength can be used .
See the examples also.
You may want to check C# Windows Forms RichTextBox cursor position also .
我不确定你的意思是“光标”还是鼠标指针。这两个术语都用来指鼠标指针,但当然“光标”过去只是指告诉您在哪里打字的小华而不实的东西。
如果您想要鼠标指针的屏幕坐标,请使用
Cursor
类的静态Position
属性(明白我的意思吗?):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 theCursor
(see what I mean?) class: