locked
Copying multiple items to the clipboard RRS feed

  • Question

  • Hi,

    I'm trying to copy some items to the clipboard using rtf format.

    when I paste it to Microsoft Word, it works just fine, but when I paste it to an app. that does not support rtf format (e.g. notepad) it does not paste the text.

    I tried to use the following code to set both rtf and text to the clipboard:

    Clipboard.SetDataObject(new DataObject(DataFormats.Text, MyString));

    Clipboard.SetDataObject(new DataObject(DataFormats.Rtf, MyRtf));

    but unfortunatly, the second statement overwrites the first one meaning only the rtf text will be saved on the clipboard.

    if I switch both statements, only the simple string is saved to clipboard.

    Is there a reason for the cliboard not to support two types of items simultaneously?

    thanks,

    James.

    Wednesday, March 14, 2007 3:55 PM

Answers

  • try:


    string MyString = "Hello World";
    string MyRtf = @"{\rtf1\ansi{\colortbl ;\red255\green0\blue0;}\cf1\fs20 Hello\cf0, \i World\i0\par}";
    Clipboard.Clear();
    IDataObject clips =
    new DataObject();
    clips.SetData(DataFormats.Text, MyString);
    clips.SetData(DataFormats.Rtf, MyRtf);
    Clipboard.SetDataObject(clips,
    true);


     

     

    (

    Wednesday, March 14, 2007 4:34 PM

All replies

  • try:


    string MyString = "Hello World";
    string MyRtf = @"{\rtf1\ansi{\colortbl ;\red255\green0\blue0;}\cf1\fs20 Hello\cf0, \i World\i0\par}";
    Clipboard.Clear();
    IDataObject clips =
    new DataObject();
    clips.SetData(DataFormats.Text, MyString);
    clips.SetData(DataFormats.Rtf, MyRtf);
    Clipboard.SetDataObject(clips,
    true);


     

     

    (

    Wednesday, March 14, 2007 4:34 PM
  • Thanks a lot,

    it solved my problem.

     

    james

    Thursday, March 15, 2007 9:25 AM
  • Hi James

    This one not working for me! i hv to copy a image and a string to the clipboard at tha same time!

    using

    (MemoryStream ms = new MemoryStream())

    {

    DB_User_chart.SaveImage(ms,

    ChartImageFormat.Bmp);

    Bitmap bm = new Bitmap(ms);

    string MyString = "Hello World";

    Clipboard.Clear();

    IDataObject clips = new DataObject();

    clips.SetData(

    DataFormats.Bitmap, bm);

    clips.SetData(

    DataFormats.Text, MyString);

    Clipboard.SetDataObject(clips, true);

    }


    BY Amal

    Friday, March 23, 2012 6:52 AM