Winforms RichTextBox没有';t正确更新插入符号位置

Winforms RichTextBox没有';t正确更新插入符号位置,winforms,c++-cli,richtextbox,caret,Winforms,C++ Cli,Richtextbox,Caret,我有一个处理程序使用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->Selec

我有一个处理程序使用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第一次调用时的位置。重新绘制文本框似乎也没有任何效果。

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


SelectionStart+=(长度(“SomeOfMyOwn”)

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

事实上,我关闭了。第二个GetTextAtLoc调用选择“SomeOfMyOwn”,随后的SelectionLength查询获取上述文本的长度。RTB有时在选择时可能有点“阴暗”;您是否使用Select(SelectionStart,SelectionLength)尝试过Select方法