问题
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