c# - How to create a custom clipboard format in a WinForms app -
take @ image:
the screenshot generated copying 1 of contacts in skype list. data contains raw bytes containing information skype apparently finds useful (in case, contact name, along size of name).
i accomplish myself.
here's code used in attempt copy clipboard
byte[] bytes = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }; clipboard.setdata("my data", bytes);
which copy clipboard. however, dataobject entry along data added it, rather raw bytes:
the top half see. bottom half when take screenshot of screen. notice raw bitmap data.
can done in .net?
the bytes serialization headers. see note msdn documentation on clipboard
class (emphasis mine):
an object must serializable put on clipboard. if pass non-serializable object clipboard method, method fail without throwing exception. see system.runtime.serialization more information on serialization. if target application requires specific data format, headers added data in serialization process may prevent application recognizing data. preserve data format, add data byte array memorystream , pass memorystream setdata method.
so solution this:
byte[] bytes = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }; memorystream stream = new memorystream(bytes); clipboard.setdata("my data", stream);
Comments
Post a Comment