|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Setting multiple formats on ClipboardThe help for the Windows.Forms.Clipboard class states, "Place data on the
clipboard in multiple formats to maximize the possibility that a target application, whose format requirements you might not know, can successfully retrieve the data." So how do you do that? I want to place text and an image on the Clipboard at the same time. But, when I run the following test code only the text is on the Clipboard: Dim bmp As New Drawing.Bitmap(100, 100, Imaging.PixelFormat.Format24bppRgb) Call Windows.Forms.Clipboard.SetDataObject(bmp) Call Windows.Forms.Clipboard.SetDataObject("1,2,3,4,5") Am I doing something wrong? Thanks, Lance Hi
We can build a dataobject of multiple formats. Here is the code. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' Creates a new data object, and assigns it the component. Dim myDataObject As New DataObject ' Adds data to the DataObject, and specifies no format conversion. myDataObject.SetData(DataFormats.UnicodeText, False, "My Unicode data") myDataObject.SetData(DataFormats.Text, False, "My Text") myDataObject.SetData(DataFormats.Bitmap, False, New Bitmap("c:\temp\test.jpg")) Clipboard.SetDataObject(myDataObject) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim ido As IDataObject = Clipboard.GetDataObject() Dim arrayOfFormats As String() = ido.GetFormats() For Each str As String In arrayOfFormats MsgBox(str) Next End Sub Best regards, Peter Huang Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights. Thank you Peter, this is very helpful for me as well!
However, I have a further question: is it possible to set priorities on the different data formats? I put CSV (in a memorystream) and plain text on the clipboard, and when pasting to excel it seems to prefer the plain text over the csv format. I really want it to use the CSV as default, but I can not acheive this by manipulating excel, since we are restricted not to automate or control other apps from the one I'm writing. Also, it seems the memrystream looses encodings. Our users are swedish and some of the characters in our code page are scrambled when pasting :-( Any ideas? br Carolina Show quoteHide quote ""Peter Huang" [MSFT]" wrote: > Hi > > We can build a dataobject of multiple formats. > Here is the code. > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > ' Creates a new data object, and assigns it the component. > Dim myDataObject As New DataObject > > ' Adds data to the DataObject, and specifies no format conversion. > myDataObject.SetData(DataFormats.UnicodeText, False, "My Unicode > data") > myDataObject.SetData(DataFormats.Text, False, "My Text") > myDataObject.SetData(DataFormats.Bitmap, False, New > Bitmap("c:\temp\test.jpg")) > > Clipboard.SetDataObject(myDataObject) > > End Sub > > Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button2.Click > Dim ido As IDataObject = Clipboard.GetDataObject() > Dim arrayOfFormats As String() = ido.GetFormats() > For Each str As String In arrayOfFormats > MsgBox(str) > Next > End Sub > > Best regards, > > Peter Huang > Microsoft Online Partner Support > > Get Secure! - www.microsoft.com/security > This posting is provided "AS IS" with no warranties, and confers no rights. > > |
|||||||||||||||||||||||