473,405 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Setting multiple formats on Clipboard

The 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

Nov 21 '05 #1
4 3152
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.

Nov 21 '05 #2
Thanks a lot for the sample. That is exactly what I was looking for.

Lance

Nov 21 '05 #3
Hi

I am glad that my suggestion helped you.

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.

Nov 21 '05 #4
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

""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.

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Max Weber | last post by:
Try to run the code below in a page. You will notice than when you switch the multiple attribute of the SELECT tag, only one option is displayed as selected although multiple options have ben...
5
by: social_engin33r | last post by:
Hello, I've been asked to help someone set up a database. One of the fields in the database is a text field that holds data imported in this format: 11-A-11-11 The users prefer to see the...
2
by: Harag | last post by:
I need to set multiple Fontsyle enums individually but so far I have found that you can only set a Fontyle on creation of a new Font. My one other option is to build a function to to select...
0
by: Hai NIng | last post by:
Does any one know how to implement a multiple-storage clipboard, sort of like the clipboard in office where it can hold multiple number of text/image/custom data, etc.? Thanks. - Harry
0
by: Next | last post by:
Hello, I am trying to uncheck the archive box and check the compress box for a given file. I am having trouble. It seems I can uncheck the archive box but nothing I've tried will check the...
4
by: fred | last post by:
I am trying to put a FileDrop format and a Text format dataobject onto the clipboard so that they are both available. I seem to be able to do one or the other but when I try to put both on only...
1
by: ljlevend | last post by:
The 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...
1
by: zorro | last post by:
Greetings, I want users to select the duration time of their sessions. I'm able to do it by setting the PHPSESSID cookie duration. Is this reliable, or is it not recommended for some reason? ...
1
by: rmiah | last post by:
Hi I am using Visual Basic 2005. I have a stream of data which I want to set over 20 label.text properties. Instead of setting the data individually ie label1.text = ....label2.text=........
0
by: waldedg | last post by:
I have a ListBox set as Multiselect. I am populating the table thruough asp.net code. But I am using another dataset to get the items that should be selected. The only item that ends up selected is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.