+ -
当前位置:首页 → 问答吧 → RICHEDIT的输入位置不随Caret的变化而变化?

RICHEDIT的输入位置不随Caret的变化而变化?

时间:2011-12-07

来源:互联网

C/C++ code
GetDlgItem(IDC_RICHEDIT21)->SetFocus();
CPoint ptPos=GetCaretPos();
SetCaretPos(CPoint(1,ptPos.y+16));


这是在一个按钮单击事件响应中的代码。
第一次单击按钮时插入符会相应的改变位置,但是输入位置并没有改变,依然跟在上次输入的末尾;第二次单击按钮时连插入符都不动。
求解。谢谢。

VC2008,richedit多行为True。

作者: mkdym   发布时间: 2011-12-07

想修改edit中的文字,可以使用ReplaceSel

作者: jennyvenus   发布时间: 2011-12-08

但是If there is no current selection, the replacement text is inserted at the insertion point, that is, the current caret location.
我是想插入文字,所以得设置caret的位置。
怎么办啊?

作者: mkdym   发布时间: 2011-12-08

使用ReplaceSel和我自行输入的所出现的caret位置的问题是一样的。

作者: mkdym   发布时间: 2011-12-08

replacesel 之前 先 setsel一下。

作者: jennyvenus   发布时间: 2011-12-08

to jennyvenus:
我用你的方法实现了
C/C++ code
GetDlgItem(IDC_RICHEDIT21)->SetFocus();
static int curLineIndex=0;
int lineCount=m_ctrl_richedit.GetLineCount();
if (curLineIndex==lineCount)
{
    curLineIndex=lineCount-1;
}
int chIndex=m_ctrl_richedit.LineIndex(curLineIndex);
m_ctrl_richedit.SetSel(chIndex,chIndex);
++curLineIndex;


但是还是想问为什么设置插入符位置的方法就不行呢

作者: mkdym   发布时间: 2011-12-08

看不明白。。

作者: seaofhero   发布时间: 2011-12-08