how to cut and past to richtextbox in vb.net?

in the menu item to cut text simply:
ClipBoard.SetDatObject(RichTextBox.SelectedText)
RichTextBox.SelectedText = ""

to paste:
VB.NET:
Dim iData As IDataObject = Clipboard.GetDataObject()
    
    ' Determines whether the data is in a format you can use.
    If iData.GetDataPresent(DataFormats.Text) Then
        ' Yes it is, so display it in a text box.
        RichTextBox.Text = CType(iData.GetData(DataFormats.Text), String)
    End If
 
If you're not dealing with more complex data types you need to interpret, just use:
RichTextBox.Cut()
RichTextBox.Copy()
RichTextBox.Paste()
 
Still very useful to check with IDataObject and in some cases do custom interpretations of the source both when getting data from clipboard and when putting data there.
 
i used the SelectedText property because if you paste something and there isnt any text selected then it inserts the new text where the cursor is and doesnt remove anything
 
BradleyOng83 said:
because i use AxRichtextbox it cannot use selecttext..

that would have helped knowing from the start, i've never used the AxRichtextbox, do you have a weblink to it? i'm sure they'd have a list of supported properties on their site and it'd just be a matter of seeing what's available and putting two and two together
 
would it be possible for you to use the RichTextBox that comes in the toolbar with the IDE? i cant help you with the AxRichTextBox because i dont know what it can and cant do
 
Back
Top