如何在C#中的richtextbox中显示光标的位置

发布于 2024-11-27 20:21:20 字数 136 浏览 5 评论 0原文

我正在寻找针对这个问题的快速解决方案。在我的应用程序中,我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

当梦初醒 2024-12-04 20:21:20

TextBoxBase.SelectionStartTextBoxBase.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 .

尐偏执 2024-12-04 20:21:20

我不确定你的意思是“光标”还是鼠标指针。这两个术语都用来指鼠标指针,但当然“光标”过去只是指告诉您在哪里打字的小华而不实的东西。

如果您想要鼠标指针的屏幕坐标,请使用 Cursor 类的静态 Position 属性(明白我的意思吗?):

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

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文