NETCF 2.0 Clipboard Operations





6
Date Submitted Mon. Feb. 20th, 2006 7:04 PM
Revision 1 of 1
Beginner RRSands
Tags Clipboard | CSharp | NETCF2.0
Comments 0 comments
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.

        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());
        }
 

Rick Sands

www.pdatoolbox.org

Comments

There are currently no comments for this snippet.

Voting