Saturday, June 6, 2009

Programatically adding text to clipboard

Scenario:
For one of my tiny console application , I wanted to make it easier for my end users . This console application generates some text and users need to copy it to clipboard and then paste it on to another application. Thought of making it simpler.

Solution:
I discovered its preety easy with clipboard class

Code:

using System.Window; // For this example, the data to be placed on the clipboard is a simple
// string.
string textData = "I want to put this string on the clipboard.";

// After this call, the data (string) is placed on the clipboard and tagged
// with a data format of "Text".
Clipboard.SetData(DataFormats.Text, (Object)textData);
Article:
Clipboard class
Follow on Twitter

0 comments: