这几天需要实现文本框中选中某些个字符
使用 CEdit的SetSel()函数无疑
void SetSel(int nStarChar,int nEndChar,BOOL bNoscroll=FALSE)
nStarChar:选中字符的起始位置。
nEndChar:选中字符的终止位置。
最开始仅仅使用这个函数无法实现,在网上搜了好久得出的结果“与CEdit的SetFocus配合使用”,通过这种方法确实实现了字符选中,但是我不希望CEdit获取焦点。
最后仔细检查文本框的属性,有一个No Hide Selection,默认设置为False,将其修改为True
看一看这个属性的作用吧
TextBoxBase.HideSelection Property
Property Value
true if the selected text does not appear highlighted when the text box control loses focus;false, if the selected text remains highlighted when the text box control loses focus. The default istrue.
Remarks
You can use this property to keep text highlighted in a text box control while another form or a dialog box has focus, such as a spelling checker dialog box.
总算解决了,希望对纠结于这个问题的朋友们有所帮助
MFC中文本框的SetSel()函数
最新推荐文章于 2024-06-17 16:49:45 发布