头文件 #ifndef _DISCOPYTEXTCTRL_ #define _DISCOPYTEXTCTRL_ #include "wx/wx.h" #include "wx/textctrl.h" class MyTextCtrl: public wxTextCtrl { public: MyTextCtrl() : wxTextCtrl(){} MyTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = _T("TextCtrl")) : wxTextCtrl() { Create(parent, id, value, pos, size, style, validator, name); } bool Create(wxWindow* parent, wxWindowID id, const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = _T("TextCtrl")); virtual ~MyTextCtrl() {} void OnRightDown(wxMouseEvent& event); void OnKeyKDown(wxKeyEvent& event); private: DECLARE_CLASS(MyTextCtrl) DECLARE_EVENT_TABLE() }; #endif 源文件 #include "DisCopyTextCtrl.h" IMPLEMENT_CLASS(MyTextCtrl, wxTextCtrl) BEGIN_EVENT_TABLE(MyTextCtrl, wxTextCtrl) EVT_RIGHT_DOWN(MyTextCtrl::OnRightDown) EVT_KEY_DOWN(MyTextCtrl::OnKeyKDown) END_EVENT_TABLE() bool MyTextCtrl::Create(wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) { if (!wxTextCtrl::Create(parent, id, value, pos, size, style, validator, name)) return FALSE; return TRUE; } void MyTextCtrl::OnRightDown(wxMouseEvent& event) { return; } void MyTextCtrl::OnKeyKDown(wxKeyEvent& event) { if (event.ControlDown()) { if (event.GetKeyCode() == 'V') { return; } } event.Skip(); }