当光标改变位置时发生事件 wxWidgets 文本框?
在wxWidgets中,如何检测wxTextCtrl中光标位置何时发生变化?我查看了手册,找不到任何与之相关的事件,但也许我错过了另一种方法。
In wxWidgets, how can I detect when the cursor position changed in a wxTextCtrl? I looked at the manual and couldn't find any event relating to it, but maybe there is another way I've missed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于 wxTextCtrl 继承自 wxWindow,因此您可以将以下鼠标事件与该控件绑定:
http://docs.wxwidgets.org/2.8/wx_wxmouseevent.html#wxmouseevent
我认为您感兴趣的是 EVT_MOTION(func)。但是,我从未使用过此事件,因此我无法确定它是否仅在其绑定的窗口内的鼠标运动(这将是更有趣的方法)或全局鼠标移动时引发。
Since a wxTextCtrl inherits from wxWindow, you can bind the following mouse events with that control:
http://docs.wxwidgets.org/2.8/wx_wxmouseevent.html#wxmouseevent
I think the one you're interested in is EVT_MOTION(func). However, I have never used this event so I can't say for sure if it is only raised on mouse motion inside the window it is binded to (which would be the more interesting approach) or global mouse movement.
我相当确定他指的是插入点光标,在这种情况下,没有 wxWidgets 事件来改变它的位置。此外,虽然 wxTextCtrl::SetInsertionPoint() 和 wxTextCtrl::SetInsertionPointEnd() 是可以被覆盖的虚拟方法,但这仅捕获以编程方式更改的情况,而不是通过取决于本机平台参与的各种操作(这可能是此事件的原因)目前 wxWidgets 中不存在)。
我现在能想到的便携式捕获所有插入点更改的最佳解决方案是使用计时器连续轮询插入点位置。如果您在多个位置需要此功能,您可以使用内置的此功能派生您自己的 wxTextCtrl,该功能会生成您自己的自定义事件。
我个人的建议是寻找一种替代解决方案来解决您的问题,并且不需要始终知道插入点位置。您确定您确实需要知道插入点位置,而不仅仅是文本控件中的值何时发生变化吗?
I'm fairly certain he means the insertion point cursor, in which case, there isn't a wxWidgets event for changes in it's position. Additionally, while wxTextCtrl::SetInsertionPoint() and wxTextCtrl::SetInsertionPointEnd() are virtual methods that can be overwritten, this only catches situations where it's changed programmatically and not through various actions depending on the native platform involvement (which are likely why this event doesn't exist in wxWidgets currently).
The best solution I can think of to portably catch all insertion point changes right now is to continuously poll the insertion point position with a timer. You could derive your own wxTextCtrl with this functionality built in that generates your own custom event if you need this feature in more than one location.
My personal recommendation would be to look for an alternative solution to your problem that doesn't require knowing the insertion point position at all times. Are you sure that you actually need to know the insertion point position and not just when the value in the text control changes?