If this is a Windows Form and you want your user to be able to right-click and copy the text, then you can add a ContextMenuStrip to the label with a 'Copy' ToolStripItem whose click event is handled by a simple method which copies the Label.Text to the Clipboard.
-
-
///<summary>ContextMenu to allow user to copy label text to clipboard.</summary>
-
ContextMenuStrip createCopyMenu(EventHandler specificAction) {
-
ContextMenuStrip contextMenu = new ContextMenuStrip();
-
ToolStripItem copyCmd = contextMenu.Items.Add("Copy");
-
copyCmd.Click += specificAction;
-
return contextMenu;
-
}
-
-
///<summary>Copy Label text to clipboard when ContextMenu.Copy is clicked.</summary>
-
void copyAddressCmd_Click(object sender, EventArgs e) {
-
Clipboard.SetDataObject(myAddressLabel.Text, false);
-
}
-
-
myAddressLabel.ContextMenuStrip = createCopyMenu(copyAddressCmd_Click);
-
The above code allows you to apply a context menu to several controls, each with their own EventHandler for clicking on the Copy command.
(Sorry, just noticed you were looking for VB.Net code. Feel free to post your port if you find it helpful.)