backup_restore clipboard

  • Thread starter =?ISO-8859-1?Q?M=E9sz=E1ros_Tam=E1s?=
  • Start date
?

=?ISO-8859-1?Q?M=E9sz=E1ros_Tam=E1s?=

Hi!

Can I save and restore the content of the clipboard without dealing with
the format it stores? I use the clipboard for data exchange between
applications (this is the only way), and I would like to keep the
previous content of the clipboard. Any examples I've found build on the
format of the data, but I can't now in advance, what type of data on the
clipboard will be. I can't even save and restore a part of simple
formatted text copied from winword. If I choose text format, I get
unformatted text back. If I choose Rich Text Format, I get the rtf
formatting text (eg. "{\rtf1\ansi\ansicpg1250\uc1\deff0\" ..., but not
the formatted text.

IDataObject ido = Clipboard.GetDataObject();
object savedData = ido.GetData(DataFormats.Rtf, true);
....Using clipboard for data exchange
Clipboard.SetDataObject(savedData, true);

And what if there is a bitmap or other kind of data on the clipboard?
How could I save and restore them?

Could someone send me a link where I could find solution for my problem,
or tell me what I could do?

Thank's

Tamas Meszaros
 
N

Nicholas Paldino [.NET/C# MVP]

Mészáros,

Once you get the implementation of IDataObject, you should be able to
call GetFormats to get all the formats that are on the clipboard. Once you
have those, cycle through them, and get the data, and store it somewhere.

Hope this helps.
 
D

Denny Britz

Hi,
I've found build on the
format of the data, but I can't now in advance, what type of data on the
clipboard will be. I can't even save and restore a part of simple
formatted text copied from winword.

ido.GetFormats(true) returns a string-array of all supported datatypes.
You can iterate through them and decide which one to choose.

If I choose text format, I get
unformatted text back. If I choose Rich Text Format, I get the rtf
formatting text (eg. "{\rtf1\ansi\ansicpg1250\uc1\deff0\" ..., but not
the formatted text.

string stemp = Clipboard.GetDataObject().GetData("Rich Text
Format").ToString();
DataObject data = new DataObject();
data.SetData(DataFormats.Rtf, s);
System.Windows.Forms.Clipboard.SetDataObject(data,true);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top