MFC中文本框的SetSel()函数

这几天需要实现文本框中选中某些个字符

使用 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.


总算解决了,希望对纠结于这个问题的朋友们有所帮助


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值