Storing and Retrieving Information from the Clipboard
The clipboard is used for everyday copy-and-paste operations. You can use it manually to copy things such as audio clips or just text, as shown in Listing 2. This code example uses My.Computer.Clipboard to store and retrieve information from the clipboard.
Listing 2 Storing and retrieving from the clipboard.
Try My.Computer.Clipboard.SetText("Hello, World!") Console.WriteLine("From clipboard: " + My.Computer.Clipboard.GetText()) Console.WriteLine("Press Enter") Console.ReadLine() Catch ex As Exception Console.WriteLine("Clipboard failed") End Try
Notice that I have a Try..Catch block around the clipboard use. I haven’t figured out exactly why, but the clipboard seems prone to persnickety behavior occasionally, and the Try..Catch slows unhandled exceptions.