简体   繁体   English

自定义wxTextCtrl自动完成

[英]customize wxTextCtrl autocomplete

I have a wxTextCtrl object and set it to be autocomplete 我有一个wxTextCtrl对象并将其设置为自动完成

wxArrayString _myStringArray;
_myStringArray.push_back("abc");
_myStringArray.push_back("alpha");
_myStringArray.push_back("bnm");

_myTextCtrl->AutoComplete(_myStringArray);

I type char 'a' into it. 我在其中输入char'a'。 And then a popup shown with a list of related/suggested strings (ie "abc" and "alpha"). 然后显示一个弹出窗口,其中包含相关/建议的字符串列表(即“ abc”和“ alpha”)。 Now I press 'down arrow key' in order to select a string. 现在,我按下“向下箭头键”以选择一个字符串。 The first time I press the button the "abc" string is selected. 第一次按下按钮时,选择了“ abc”字符串。 The second time I press the button the "alpha" string is selected. 第二次按下按钮时,选择了“ alpha”字符串。

The problem is changing the string selection by pressing UP and DOWN arrow keys doesn't change the text control value. 问题是通过按UP和DOWN箭头键更改字符串选择不会更改文本控件的值。 I want the text control value to be updated when the selected string changed by pressing UP and DOWN arrow key. 我希望通过按UP和DOWN箭头键更改选定的字符串时更新文本控件的值。

I thought I could do that manually if I know the event name. 我以为如果知道事件名称,就可以手动执行此操作。 So the question is: what is the event name (or event macro) of changing string selection from a popup in a wxTextCtrl by pressing UP and DOWN arrow key? 因此,问题是:通过按向上和向下箭头键从wxTextCtrl的弹出窗口更改字符串选择的事件名称(或事件宏)是什么?

Thanks 谢谢

update: I am succeded on capturing KEY DOWN event by subclassing wxTextCtrl and then add an event handler for EVT_KEY_DOWN event. 更新:通过子类化wxTextCtrl成功捕获了KEY DOWN事件,然后为EVT_KEY_DOWN事件添加了事件处理程序。

void TextCtrlChild::keyHandler(wxKeyEvent& event)
{
   int _keyCode = event.GetKeyCode();
   if(_keyCode == 315 || _keyCode == 317){ //if UP or DOWN arrow key is pressed
     //TO DO: capture the highlighted string from the popup
   }
   event.Skip();
}

Now the question is how to capture the selected/highlighted string from the popup? 现在的问题是如何从弹出窗口中捕获选定/突出显示的字符串?

The way autocompletion works is dictated by the system UI conventions, so it doesn't look like a good idea to interfere with it. 自动补全的工作方式由系统UI约定规定,因此,对其进行干扰似乎不是一个好主意。 If you really want to have immediate selection, consider using another control, such as wxChoice , instead. 如果您确实希望立即选择,请考虑使用另一个控件,例如wxChoice

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM