Create and Copy hyperlink with text/caption to Clipboard with c#
I don't know the architecture you're working with, but in any case you have just to copy the URL in the Clipboard.
For example, assuming you've got an HyperLink
control named myHyperlink and a Button
named copyButton.
When the user clicks the button you have just to use Clipboard.SetText(string)
passing to the method the URL Property of myHyperlink.
EDIT: To show an hyperlink with caption in another program like Word you have to set the text in a HTML way with a particular header.
Version:0.9
StartHTML:<<<<<<<1
EndHTML:<<<<<<<2
StartFragment:<<<<<<<3
EndFragment:<<<<<<<4
SourceURL: www.google.it
<html>
<body>
<!--StartFragment-->
<a href="http://programmers.stackexchange.com/">programmers</a></span></span>
<!--EndFragment-->
</body>
</html>
This is an example of HTML, let's try to generalize it in C#:
private const string html = @"Version:0.9
StartHTML:<<<<<<<1
EndHTML:<<<<<<<2
StartFragment:<<<<<<<3
EndFragment:<<<<<<<4
SourceURL: {0}
<html>
<body>
<!--StartFragment-->
<a href='{0}'>{1}</a>
<!--EndFragment-->
</body>
</html>";
And then use it as follows:
string link = String.Format(html, "http://www.google.it", "Google");
Clipboard.SetText(link, TextDataFormat.Html);