我用wxEVT_SET_FOCUS表示wxTextCtrl in wxWidgets。我需要做的是,当用户单击textctrl时,我必须打开一个新窗口并从textctrl中移除焦点,以便只执行FocusHandler函数一次。是否有从wxTextCtrl中移除焦点的功能?
Using this connect event in constructor
//Connect Events
m_passwordText->Connect(wxEVT_SET_FOCUS, wxFocusEventHandler(MyFrame::OnPasswordTextBoxSetFocus), NULL, this);
void MyFrame::OnPasswordTextBoxSetFocus(wxFocusEvent& event)
{
if(some condition is true)
//code to open a new window
event.Skip()
// is there any option to remove focus from password textCtrl so that once a new window opens
//I can remove focus from password and avoid executing this function again and again.
// If new window opens for the first time, I perform the operation and close it
// then also it opens again as control is still in password textbox.
//Is there any way to resolve this?
}基本上,我希望在打开新窗口后停止多次执行处理程序函数,而不将wxeVT_SET_FOCUS与wxTextCtrl断开连接。
发布于 2018-08-08 18:23:22
每次控件获取或松开焦点时,都会触发焦点事件,而您的处理程序就会开始操作。
这一焦点事件有一些原因。最麻烦的是在创建和删除新窗口时,因为它可能会生成自己的焦点事件,而您的处理程序可能会处理所有这些事件。有个重新进入的问题。
我们使用一个标志来处理重新进入,它告诉我们是否在重新进入的情况下。
void MyFrame::OnPasswordTextBoxSetFocus(wxFocusEvent& event)
{
static bool selfFired = false; //our flag
event.Skip(); //always allows default processing for focus-events
if ( event.GetEventType() == wxEVT_KILL_FOCUS )
{
//Nothing to do. Action takes place with wxEVT_SET_FOCUS
return;
}
//Deal with re-entrance
if ( !selFired )
{
if (some condition)
{
selfFired = true;
//Open a new window.
//Pass 'this' to its ctor (or similar way) so that new window
//is able to SetFocus() back to this control
newWin = open a window...
newWin->SetFocus(); //this may be avoided if the new window gains focus on its own
}
}
else
{
//restore the flag
selfFired = false;
}
}https://stackoverflow.com/questions/51752299
复制相似问题