473,809 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to detect BOTH text and (multiple?) images in the clipboard

5 New Member
Hi gurus

.Net 2.0

I'm on a project where I need to be able to detect if my clipboard contains BOTH images AND text (eg. when copying from a web page).

For some reason Clipboard.Conta insImage() only returns true if the clipboard contains one and only one image. I use Clipboard.GetDa taObject().GetD ataPresent(Data Formats.Text) to detect the presence of text.

What I need to figure out is how to detect if the clipboard contains one or more images and/or text at the same time.

Can anyone help me out?

Thanks in advance...

./kroogar
Sep 1 '09 #1
8 8095
GaryTexmo
1,501 Recognized Expert Top Contributor
Have a look at this article...

http://www.codeproject.com/KB/shell/clipboard01.aspx

Good luck! :)
Sep 1 '09 #2
kroogar
5 New Member
Thanks for the reply GaryTexmo but unfortunately it didn't help :-(

The example works only when trying to detect bitmap images but pasting any other format doesn't work. E.g. when copying both images and text from Internet Explorer the sample code is inadequate.

So I'm back to square one :-(
Sep 2 '09 #3
GaryTexmo
1,501 Recognized Expert Top Contributor
Darn, I had thought the section entitled Maintain multiple formats in the Clipboard where they paste both images and text was right up your alley, but I guess that's a single instance of one or the other, isn't it?

I don't know much about this object. I was looking at it but I couldn't see a way to find the data that was actually on the clipboard. It seems the Clipboard class only lets you ask for a type of data... which is downright weird if you ask me. I googled around and couldn't see anything helpful.

If you do copy a group of images and pictures from IE, what exactly do you find in the Clipboard with your code?
Sep 2 '09 #4
Plater
7,872 Recognized Expert Expert
Here's a little snipit that might help you out:
Expand|Select|Wrap|Line Numbers
  1. DataObject ido = (DataObject)Clipboard.GetDataObject();
  2. string[] formats = ido.GetFormats();
  3. foreach (string f in formats)
  4. {
  5.    object o = ido.GetData(f);
  6. //you can use o.GetType() to see the actual type, but the string f should also have it
  7. }
  8.  
Sep 2 '09 #5
kroogar
5 New Member
Thanks for your effort guys - appreciate it

Using Platers snippet (thanks P) I get the following result when copy/pasting from Firefox (FF) and Internet Explorer (IE). The results are "f" / "o.GetType( )" with reference to Platers code. Trouble is that I cannot know where the client is copying from hence I would not know the formats to check for in advance...

Here are the results:

Copy/paste from FF - text and images
=============== =============== ========
text/html / System.IO.Memor yStream
HTML Format / System.String
text/_moz_htmlcontex t / System.IO.Memor yStream
text/_moz_htmlinfo / System.IO.Memor yStream
System.String / System.String
UnicodeText / System.String
Text / System.String
text/x-moz-url-priv / System.IO.Memor yStream


Copy/paste from IE - text and images
=============== =============== ========
System.String / System.String
UnicodeText / System.String
Text / System.String
HTML Format / System.String
Rich Text Format / System.String


Copy/paste from FF - single picture
=============== =============== ========
application/x-moz-nativeimage / object is null
DeviceIndepende ntBitmap / System.IO.Memor yStream


Copy/paste from IE - single picture (same picture as above)
=============== =============== ========
UntrustedDragDr op / System.IO.Memor yStream
FileDrop / System.String[]
FileNameW / System.String[]
FileName / System.String[]
UniformResource LocatorW / System.IO.Memor yStream
DeviceIndepende ntBitmap / System.IO.Memor yStream
HTML Format / System.String


Copy/paste from FF - text only
=============== =============== ========
text/html / System.IO.Memor yStream
HTML Format / System.String
text/_moz_htmlcontex t / System.IO.Memor yStream
text/_moz_htmlinfo / System.IO.Memor yStream
System.String / System.String
UnicodeText / System.String
Text / System.String
text/x-moz-url-priv / System.IO.Memor yStream


Copy/paste from IE - text only
=============== =============== ========
System.String / System.String
UnicodeText / System.String
Text / System.String
HTML Format / System.String
Rich Text Format / System.String
Sep 3 '09 #6
GaryTexmo
1,501 Recognized Expert Top Contributor
Do you need to know in advance? With Platter's code, you can just loop through the types on the Clipboard and use a switch statement on the type to take the appropriate action... couldn't you?

You shouldn't need to know where it's copying from, just take the appropriate action with whatever you have at any given time.
Sep 3 '09 #7
kroogar
5 New Member
@GaryTexmo
Well... I need to know prior to pasting as pasting of content containing other than (formatted) text OR a single image has to be prevented and the user has to get a warning that he/she is pasting "illegal" content.

@GaryTexmo
I guess my two main sources for content would be a browser and MS Word. I was thinking of detecting the content as HTML and parsing that for existense of <img> tags (if possible) and in the other case (Word) extracting the clipboard content into some sort of officeautomatio n object and parsing that as XML...

Any thoughts on this approach?
Sep 4 '09 #8
kroogar
5 New Member
To stop further investigation into this issue let me start by saying that I have found a suitable workaround.

The project I'm working on has to produce a Word add-in to "transform" Word into an advanced XML editor. To do this we are using VSTO (an MS Office framework from Microsoft). Working with Word is done using a Range object that has a couple of useful collections: Hyperlinks and InlineShapes. Using these I can determine if a pasted Range contains one or more Hyperlinks and/or InlineShapes. If that is the case then reject the paste.

Thanks guys for your effort!

Have a nice weekend!
Sep 4 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2597
by: Meikel | last post by:
I created a ClipboardUtils class which makes it easy to copy Strings or images to the clipboard. I don't claim that it's no way perfect, but has been useful in my applications so far. If you try it out and have improvement suggestions, let me know. It can also copy a graphical image of any JComponent to the clipboard. I also wondered how I could copy text AND images to the clipboard at the same time (e.g. an image with some explanatory...
157
16468
by: Dennis | last post by:
Is there some way --using, say, DOM or javascript-- to detect the current pixel width and/or height of a relatively sized table or of one of its columns or rows. I'm going to be writing javascript to adjust my page to the viewer's browser window dimensions and this would sure be great information to have. Thanks .... Dennis
4
32294
by: Risto Heinonen | last post by:
Hi. I have a web page that has images and text. I can carefully select one image and the on the right of the image and then copy & paste to Word. Is it possible to make javascript do the same: select the same area (divided by <div> tag) and copy to clipboard? So far I succeeded to make the script to copy the area inside <div> but it was plain html-text.
8
2461
by: Chris Beall | last post by:
I'm struggling with how to handle, on a web page, images that contain text that the user must be able to read. Examples: tombstone photos, photos or scans of historic documents (handwritten or typed), a map with place names, route numbers, etc. (An appropriate alternative for audio UAs would be provided and is not a part of my concern). I see two ways to handle these images: 1. Dynamic scaling, with the source image containing enough...
7
18044
by: William Gill | last post by:
Is there a simple way to cut and paste from a tkinter text widget to an entry widget? I know I could create a mouse button event that triggers a popup (message widget) prompting for cut/paste in each of the widgets using a temp variable to hold the text, but I don't wnat to reinvent the wheel if there already is something that does the job. Thanks, Bill
1
8107
by: Blog the Haggis | last post by:
Hi everyone, The program I am writing has a rich text window showing particular types of data message, and my plan is to insert a small BMP image before each message depending on its type. So far the images are showing up fine, but when you click the image it allows you to resize the BMP to arbitrary dimensions. Is there a way to gain access to the properties of these images at run time
2
3750
by: jmDesktop | last post by:
I have two listview controls. I have three items of text. I can drag and drop the listview items between each other, back and forth. But the images from the imagelist do not copy over from listview1 to listview2, only the text does. Both listviews have their smallimagelist as the single imagelist I have. Here is my code and thank you for any help. private void listView1_ItemDrag(object sender, ItemDragEventArgs e) { int max =...
0
2001
by: Robert | last post by:
Hi! I want to fill the clipboard programmatically in oder to manual copy the data to word. The data consists of cells of a grid which contains text or images. Using the standard copy/paste of the dataGridView only the text-cells are copied and pasted in word, the image-cells are empty. How can I build an IDataObject that can contain text and images like it is possible when copy from word to word?
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10379
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7660
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3014
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.