简体   繁体   中英

How to copy richtextbox content with link?

I want to copy richtextbox content with keeping format same and hyperlinks. But it is been copied as a plain text without hyperlinks. I am using linklabel in richtextbox.

private void Bttn_copy_Click(object sender, EventArgs e)
    {
        richtxtbx_email.SelectAll();

        Clipboard.Clear();
        Clipboard.SetText(richtxtbx_email.SelectedRtf, TextDataFormat.Rtf);
    }

and trying this:

DataObject dto = new DataObject();
dto.SetText(mesrtf, TextDataFormat.Rtf);
dto.SetText(mes, TextDataFormat.UnicodeText);
Clipboard.Clear();
Clipboard.SetDataObject(dto);

Can you help me solve this issue ?

Hyperlinks are just a way of a using hypertext links inside an editor that is capable of rendering them as such.

When copying the text from the textbox, you can only copy the plaintext itself.

Note that RichTextBox.SelectedRtf is property of type string.

RichTextBox doesn't hold a hyperlink like HTML does.

It only detects if a certain text looks like a link and automatically colores it blue, add underline and detect if the user clicks on it.

It does so if the RichTextBox.DetectUrls Property is set to true.

If you are copying data to a new RichTextBox and don't see the link that was detected in the other RichTextBox then you just need to set this property to true before you copy the text.

On the other hand, if you need real links so that the text is one thing and the link is another have a look here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM