RichTextBox 未正确更新插入符位置

发布于 2024-08-29 16:04:47 字数 443 浏览 3 评论 0原文

我有一个使用 WinForms RTB 的 keyDown 事件的处理程序,它具有以下代码:

GetTextAtLoc(RTB->SelectionStart); // selects some text at the caret's position
RTB->SelectedText = "SomeOfMyOwn";
GetTextAtLoc(RTB->SelectionStart); // selects the replacement string
RTB->SelectionStart += RTB->SelectionLength - 1;

虽然此代码似乎完成了其工作(SelectionStart/Length 属性已正确更新),但插入符号不会移动到新字符串的末尾- 它显示了 GetTextAtLoc 第一次调用时的位置。重画文本框似乎也没有任何效果。

I have a handler consuming the keyDown event of a WinForms RTB, that has the following code:

GetTextAtLoc(RTB->SelectionStart); // selects some text at the caret's position
RTB->SelectedText = "SomeOfMyOwn";
GetTextAtLoc(RTB->SelectionStart); // selects the replacement string
RTB->SelectionStart += RTB->SelectionLength - 1;

While this code seems to do its job (SelectionStart/Length properties are updated correctly), the caret doesn't move to the end of the new string - It says right where it was at the time of GetTextAtLoc's first call. Redrawing the textbox doesn't seem to have any effect either.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

墨洒年华 2024-09-05 16:04:47

问题似乎已经解决了。不幸的是,不知道是什么带来了这种变化。关闭此线程。

The problem seems to have fixed itself. Dunno what brought about the change, unfortunately. Closing this thread.

终弃我 2024-09-05 16:04:47

您没有指定新长度(因此:1-1=0)。尝试如下:

SelectionStart += (length("SomeOfMyOwn"))

You did not specify the new length (and is therefor: 1-1=0). Try something like:

SelectionStart += (length("SomeOfMyOwn"))

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