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?).
A
RichtTextBox
doesn't have aSelection
property, hence the error message.It does have a
SelectionStart
andSelectionLength
property, which you can use to get the selection text yourself:Or simply use
SelectedText