How to determine is there any data stored on the clipboard in C#?
Many thanks for your replying.

解决方案 »

  1.   

    Using "Clipboard.GetDataObject" method.
    Sample code as follows:
    IDataObject idata = Clipboard.GetDataObject();
    if( idata != null )
    {
        //there are some data stored in clipboard
    }
      

  2.   

    It is so simple and useful.
    Thank you very much.
      

  3.   

    Clipboard.Clear();            
                IDataObject idata = Clipboard.GetDataObject();
                if (idata != null)
                {
                    MessageBox.Show("true");
                }
                else
                {
                    MessageBox.Show("false");
                }
                
                I just realize that the code will be true always.
                Please check it out.
      

  4.   

    Sample code as follows:
    Clipboard.Clear();
    IDataObject idata = Clipboard.GetDataObject();
    if (idata != null)
    {
        string[] strFormats = idata.GetFormats();
        if (strFormats.Length == 0)
        {
            //No data here
        }
    }
      

  5.   

    //How about create an IDataObject that contain the “empty” object during the //Initialize phase by following codes.Clipboard.Clear();
    IDataObject emptyClipboard = Clipboard.GetDataObject();//Then manipulate the clipboard to do whatever need to do.//Last, use the Clipboard.Equals() method to determine current clipboard status, like //following codes.bool determineData = Clipboard.Equals(emptyClipboard, idata);