我在使用 wxTextEntryDialog 和 wxTextValidator 时遇到了一个问题,在使用 wxWidgets 2.9.5 时
简而言之,wxTextValidator 似乎没有任何作用。用户可以在 wxTextEntryDialog 中输入任何内容。
// setup validator
wxString ipAddressFilter[11] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "."}; // authorized characters for IP Address
wxArrayString arraystrIPAddress(11, ipAddressFilter);
wxTextValidator txtvldIPAddress(wxFILTER_INCLUDE_CHAR_LIST); // text validator for IP Address
txtvldIPAddress.SetIncludes(arraystrIPAddress); // sets authorized characters for IP Address
// get ip from user
wxString ip;
auto dialog = new wxTextEntryDialog( this, _("Call button pressed"), _("enter ip"), ip);
dialog->SetValidator(txtvldIPAddress);
dialog->ShowModal();
ip = dialog->GetValue();
wxMessageBox( _("button call pressed."), ip , wxOK|wxICON_INFORMATION, this );
请注意 wxTextCtrl 按预期与 wxTextValidator 一起工作:
txtctrlIPAddress = new wxTextCtrl(this, -1, wxEmptyString, wxPoint(0, 5), wxSize(300, 30), wxTE_CENTRE, txtvldIPAddress);