在 WxWidgets 文本控件中按 Enter 时防止换行
我正在使用 WxWidgets 编写一个应用程序,并且遇到了多行文本控件 (wxTextControl) 的问题。它是聊天窗口中的输入字段,并且需要是多行,以防用户输入需要换行的较长消息。我希望发送事件(例如,按下“发送”按钮时执行的操作)在用户按控件中的 Enter 键时执行。我使用 wxEVT_COMMAND_TEXT_ENTER 事件进行此工作,并启用了 wxTE_PROCESS_ENTER 样式。然而,问题是,当发送命令确实被执行时,一个新的行字符 \n 也会被附加到文本中(这种情况发生在发送命令之后和我清除文本之后,导致除了一个新的字段之外的一个空字段)线)。我试图通过捕获 char 和 key down 事件来避免这种情况,但由于某种原因它们没有触发。
我只是想完全避免显示新行。有人有什么建议吗?
我正在 Windows 上进行开发,但该应用程序旨在在 WxWidgets 支持的所有平台上运行。
I am writing an application with WxWidgets, and have run into an issue with a multiline text control (wxTextControl). It is the input field in a chat window, and it needs to be multi line in case the user types a longer message that needs to wrap. I want the send event, e.g. the action that is taken when the Send button is pressed, to be executed when the user presses enter in the control. I have this working using the wxEVT_COMMAND_TEXT_ENTER event, with the wxTE_PROCESS_ENTER style enabled. However, the problem is that while the send command does get executed, a new line character \n is also appended to the text (this happens after the send command and after I have cleared the text, resulting in an empty field except for a new line). I tried to avoid this by trapping both char and key down events, but for some reason they are not firing.
I simply want to avoid the new line being shown at all. Does anyone have any tips?
I am developing on Windows, but the application is meant to run on all platforms supported by WxWidgets.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以跟踪 wxEVT_COMMAND_TEXT_UPDATED 并在输入换行符时清除编辑器(假设您在按下 Enter 时也清除编辑器)。
You might track
wxEVT_COMMAND_TEXT_UPDATED
and clear the editor when a new-line is entered (it assumes you are also clearing the editor when Enter is pressed).