473,383 Members | 1,788 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,383 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 3148
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?

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.