RichTextBox 未正确更新插入符位置
我有一个使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题似乎已经解决了。不幸的是,不知道是什么带来了这种变化。关闭此线程。
The problem seems to have fixed itself. Dunno what brought about the change, unfortunately. Closing this thread.
您没有指定新长度(因此: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"))