How to let the wxTextCtrl can select all by "ctrl+a&quo Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
00061205
Knows some wx things
Knows some wx things
Posts: 41
Joined: Mon Jun 16, 2008 3:43 am
Location: Beijing, China

How to let the wxTextCtrl can select all by "ctrl+a&quo

Post by 00061205 »

How let wxTextCtrl can select all by "ctrl+a"
Last edited by 00061205 on Thu Jul 31, 2008 5:02 am, edited 1 time in total.
Regards,

00061205
SteveDowd
Experienced Solver
Experienced Solver
Posts: 62
Joined: Wed Sep 28, 2005 3:16 pm
Location: Florida

Post by SteveDowd »

Check out wxKeyEvent:

http://docs.wxwidgets.org/stable/wx_wxk ... wxkeyevent

then handle the event by checking to see if event.CmdDown + "a" keyCode was pressed, then call wxTextCtrl::SetSelection(0, LastCharPos);
00061205
Knows some wx things
Knows some wx things
Posts: 41
Joined: Mon Jun 16, 2008 3:43 am
Location: Beijing, China

Post by 00061205 »

SteveDowd wrote:Check out wxKeyEvent:

http://docs.wxwidgets.org/stable/wx_wxk ... wxkeyevent

then handle the event by checking to see if event.CmdDown + "a" keyCode was pressed, then call wxTextCtrl::SetSelection(0, LastCharPos);
Thanks, I'll try.
Regards,

00061205
00061205
Knows some wx things
Knows some wx things
Posts: 41
Joined: Mon Jun 16, 2008 3:43 am
Location: Beijing, China

Post by 00061205 »

I solved this problem by connect the keyevent to wxTextCtrl control.

Code: Select all

Step 1
TextCtrl1->Connect(ID_TEXTCTRL1,wxEVT_CHAR,(wxObjectEventFunction)&ctrlaFrame::OnChar,NULL,this);

Step 2
void ctrlaFrame::OnChar(wxKeyEvent& event)
{   //The keycode of "ctrl+a" is 1
    if(event.GetKeyCode()==1)
        TextCtrl1->SetSelection(-1,-1); //selecte all
    event.Skip();
}
Regards,

00061205
maximand
Experienced Solver
Experienced Solver
Posts: 79
Joined: Fri Nov 11, 2011 5:44 pm
Location: Russia

Re: How to let the wxTextCtrl can select all by "ctrl+a&quo

Post by maximand »

Thanks,

My suggestion:

Code: Select all

    if (wxGetKeyState(wxKeyCode('A')) && wxGetKeyState(WXK_CONTROL))
        tcSourceTxtCtrl_->SetSelection(-1, -1); //select all
    event.Skip();
M$, VS2017, C++
Post Reply