在状态栏中显示 TRichEdit 行和列
我们正在向应用程序添加一个 ASCII 编辑器,并在 Delphi XE7 中使用 TRichEdit
。我们需要在状态栏中显示行和列,但尚未找到任何与 Key down 功能配合使用的代码。下面的代码是我们当前使用的代码。下面的代码在鼠标按下时完美运行,但按下键时不一致。
Row := SendMessage(asciieditor.Handle, EM_LINEFROMCHAR, asciieditor.SelStart, 0);
Col := asciieditor.SelStart - SendMessage(asciieditor.Handle, EM_LINEINDEX, Row, 0);
We are adding an ASCII editor to our application, and we are using TRichEdit
in Delphi XE7. We need to display the Row and Column in the status bar, but have not found any code that works with the Key down function. The code below is the current code we are using. The code below works perfect with the mouse down, but the key down is not consistent.
Row := SendMessage(asciieditor.Handle, EM_LINEFROMCHAR, asciieditor.SelStart, 0);
Col := asciieditor.SelStart - SendMessage(asciieditor.Handle, EM_LINEINDEX, Row, 0);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您想要在状态栏中的 Rich Edit 控件中显示插入符号位置时,通常的方法是使用编辑器的
OnSelectionChange
事件:每次移动插入符号位置或选择结束点时都会触发该事件,这正是您所需要的。
尝试使用鼠标和键盘事件来更新状态栏并不是一个好主意。例如,如果用户在不使用鼠标或键盘的情况下进行编辑或打字怎么办? (例如,以编程方式或使用语音识别。)
使用
OnIdle
会浪费 CPU 周期。When you want to display the caret position in a Rich Edit control in the status bar, the usual way is to use the editor's
OnSelectionChange
event:This is fired every time the caret pos or selection end point is moved, which is precisely what you need.
Attempting to keep the status bar updated using mouse and keyboard events is not a good idea. For instance, what if the user is editing or typing without using the mouse or keyboard? (For instance, programmatically or using speech recognition.)
And using
OnIdle
is a waste of CPU cycles.