Selection property not working

99封情书 提交于 2019-12-25 07:29:11

问题


string holder = richTextBox1.Selection.Text;

The .Selection produces an error :

'System.Windows.Forms.RichTextBox' does not contain a definition for 'Selection' and no extension method 'Selection' accepting a first argument of type 'System.Windows.Forms.RichTextBox' could be found (are you missing a using directive or an assembly reference?).


回答1:


A RichtTextBox doesn't have a Selection property, hence the error message.

It does have a SelectionStart and SelectionLength property, which you can use to get the selection text yourself:

string selectedText = rtb.Text.Substring(rtb.SelectionStart, rtb.Length);

Or simply use SelectedText

string selectedText = rtb.SelectedText;


来源:https://stackoverflow.com/questions/37521067/selection-property-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!