NETCF 2.0 Clipboard Operations
6
Prior to NETCF 2.0, this was a royal pain. Now, it's pretty straight-forward.
These three related functions provide basic Clipboard operations for text. While not terribly useful by themselves, they become more useful when attached to a field's context menu or, better yet, implemented in a custom control.
These three related functions provide basic Clipboard operations for text. While not terribly useful by themselves, they become more useful when attached to a field's context menu or, better yet, implemented in a custom control.
private void TextToClipboard(String Text)
{
if (Text.Length > 0)
Clipboard.SetDataObject(new DataObject(DataFormats.UnicodeText, Text));
}
private String TextFromClipboard()
{
IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(DataFormats.UnicodeText))
{
string text = (string)data.GetData(DataFormats.UnicodeText);
if (text.Length > 0)
return text;
}
return "";
}
private void ClearClipboard()
{
Clipboard.SetDataObject(new DataObject());
}






There are currently no comments for this snippet.