CEdit selects everything when it focuses

When I go to the CEdit control in my dialog box using the tab key or the arrow keys, all the text in the control is selected. This behavior is causing me problems, and I would prefer the control to simply position the cursor at the beginning (or end) of the text and not select anything. Is there an easy way to do this (e.g. a control property that I can set)?

+7
visual-c ++ mfc
source share
2 answers

I do not think that such a style exists.
But you can add the OnSetfocus handler using the wizard:

void CMyDlg::OnSetfocusEdit1() { CEdit* e = (CEdit*)GetDlgItem(IDC_EDIT1); e->SetSel(0); // <-- hide selection } 
+2
source share

Another way to achieve your goal is to prevent content selection. When navigating through controls in a dialog box, the dialog manager asks the appropriate controls for specific properties related to their behavior. By default, the edit control responds with the DLGC_HASSETSEL flag (among others) to indicate to the dialog manager that its contents should be automatically selected.

To get around this, you must subclass the edit control and process the message

+7
source share

All Articles