Title: See what kinds of data are available in the clipboard and display them in C#
This example shows how you can see what kinds of data are available in the clipboard. The program's form contains four controls that can display samples of data. They include a PictureBox, TextBox, RichTextBox, and WebBrowser.
Before the WebBrowser can display HTML loaded from code, it needs a Document object. The program gives it one by navigating to the blank page when the program starts.
private void Form1_Load(object sender, EventArgs e)
After navigation is complete, the code can use the control's Document property to display HTML.
When you click the List Formats button, the following code displays the available clipboard formats and shows samples of the kinds of data it can understand.
// List the available formats.
private void btnListFormats_Click(object sender, EventArgs e)
IDataObject data_object = Clipboard.GetDataObject();
foreach (string format in data_object.GetFormats())
This event handler gets the clipboard's data object and clears the program's ListBox. It then loops through the data formats returned by the data object's GetFormats method and displays them in the ListBox. It finishes by calling the following DisplayData method to display whatever data it can.
// Display data if possible.
private void DisplayData()
txtSample.Visible = false;
rchSample.Visible = false;
picSample.Visible = false;
wbrSample.Visible = false;
picSample.Image = Clipboard.GetImage();
picSample.Visible = true;
txtSample.Text = Clipboard.GetText(
txtSample.Visible = true;
HtmlDocument doc = wbrSample.Document;
doc.Body.InnerHtml = Clipboard.GetText(
wbrSample.Visible = true;
// Rich Text.
rchSample.Rtf = Clipboard.GetText(
rchSample.Visible = true;
This code hides the program's four display controls (so they don't clutter things up if there's no data for them to display). It then uses the Clipboard object's ContainsXxx methods to see what kinds of data are available on the clipboard. If the clipboard contains image, Unicode, HTML, or RTF data, the program displays it.
Notice that the code uses the clipboard's GetText method to get text, HTML, and RTF data. It passes GetText the kind of text it wants.
Take a look at the picture of the example program. Here I opened a Word file (included in the download) that contains an image and text in various fonts and colors. Note that the program doesn't say there is image data available in the clipboard. The selected text contains an image, but there is no image available by itself.
Also notice that the program shows that there are just over a dozen formats available, all provided by Word to the clipboard.
Download the example to experiment with it and to see additional details.