Nevron Open Vision Documentation
User Interface / Data Exchange / Clipboard
In This Topic
    In This Topic
     Clipboard Overview
    The Clipboard is a one publisher to many consumers data exchange mechanism. In clipboard data exchange neither the publisher has knowledge about the consumers, nor the consumers have knowledge about the publisher. That is why the clipboard operations are focused only on the data that needs to be exchanged. In NOV the clipboard is represented by the NClipboard static class.
     Setting Data on the Clipboard

    You publish data on the clipboard via the NClipboard.SetDataObject(NDataObject dataObject) method. It sets the specified data object on the clipboard. If null is passed the clipboard is cleared (placing an empty data object on the clipboard has the same effect). After the call the specified data object automatically becomes readonly. The following code sample publishes a text string:

    Publishing a Data Object on the Clipboard
    Copy Code
    // publish a data object on the clipboard that contains a simple string
    NDataObject dataObject = new NDataObject();
    // set data in the Unicode text format
    dataObject.SetData(NDataFormat.TextFormat, "Hello world");

     Getting Data from the Clipboard

    You consume data from the clipboard via the NDataObject NClipboard.GetDataObject() method. Its gets the current data object from the clipboard. If the clipboard clipboard is empty it will return an empty data object (i.e. will never return a null data object). The returned data object is always readonly.

    Consuming a Data Object from the Clipboard
    Copy Code
    // get a data object from the clipboard
    NDataObject dataObject = NClipboard.GetDataObject();
    // query whether it contains data in the Unicode text format
    if (dataObject.ContainsData(NDataFormat.TextFormat))
        // try to obtain the Unicode text
        // NOTE: you can also get Unicode text by using the GetText shortcut method.
        string text = (string)dataObject.GetData(NDataFormat.TextFormat);
        if (text != null)
            // successfully obtained Unicode text from the clipboard
     Clipboard Helper Methods

    Because in both the consumer and publisher roles the clipboard operations are only dealing with a single data object, the NClipboard static class provides helper methods similar to the helper methods of a NDataObject, that help you work more easily with the predefined formats. Following is a brief summary:

    • Text - string NClipbard.GetText(), NClipboard.SetText(string text) and bool NClipboard.ContainsText().
    • Raster - NRaster NClipbard.GetRaster(), NClipboard.SetRaster(NRaster raster) and bool NClipboard.ContainsRaster().
    • RTF - byte[] NClipbard.GetRTF(), NClipboard.SetRTF(byte[] rtf) and bool NClipboard.ContainsRTF().
    See Also