选择属性不起作用 [英] Selection property not working

查看:54
本文介绍了选择属性不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string holder = richTextBox1.Selection.Text;

.Selection 产生错误:

System.Windows.Forms.RichTextBox"不包含Selection"的定义,并且找不到接受System.Windows.Forms.RichTextBox"类型的第一个参数的扩展方法Selection"(您是否遗漏了)是 using 指令还是程序集引用?).

'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?).

推荐答案

RichtTextBox 没有 Selection 属性,因此出现错误消息.

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

它确实有一个 SelectionStartSelectionLength 属性,您可以使用它自己获取选择文本:

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);

或者简单地使用 SelectedText

Or simply use SelectedText

string selectedText = rtb.SelectedText;

这篇关于选择属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆