Reputation: 21
I have a wxDialog with somes wxTextCtrl in it. I need to connect events when these wxTextCtrl gain and lose focus. Specifically, each wxTextCtrl has a default Text. When user touches it for write in it, the default text disappears and it allows user to write from the beginning. This part is for wxEVT_SET_FOCUS.
Then, if user doesn't write something and leaves the wxTextCtrl, I set the default text again. And this part is for wxEVT_KILL_FOCUS. However, I couldn't connect the textctrl with the events. I already tried:
Connect( wxTXTCRLID , wxEVT_SET_FOCUS , wxFocusEventHandler(MyDialog::OnFocus) , nullptr , this );
This too:
Bind( wxEVT_SET_FOCUS , &MyDialog::OnFocus , this , wxTXTCRLID );
With a event table too:
BEGIN_EVENT_TABLE( MyDialog , wxDialog )
EVT_SET_FOCUS( MyDialog::OnFocus )
END_EVENT_TABLE()
And this:
BEGIN_EVENT_TABLE( MyDialog , wxDialog )
EVT_COMMAND_SET_FOCUS( wxTXTCRLID , MyDialog::OnFocus )
END_EVENT_TABLE()
In event table examples, I made sure to declare it in the header file. But none of these worked. My OS is Ubuntu 14.04 If you need more information just let me know.
Upvotes: 1
Views: 341
Reputation: 22688
wxFocusEvent
is not a wxCommandEvent
so it won't be propagated to the parent by default and you will never get it for the child window in the dialog. You must call Bind()
on the child control and not the dialog itself (and you can't do this easily with the event tables).
However before you change this, I think there is a much simpler and better solution: just use SetHint() and don't bother with implementing support for the text entry hints yourself at all.
Upvotes: 1