Solved

Adding an image & text into the clipboard

Posted on 2006-07-20
22
1,686 Views
Last Modified: 2008-01-09
Good Day Experts...

How do i go about adding an image and text into the clip board at the same time?

Currently i have a RTE & an Image...
The image gets the companies logo and the RTE has the companies description

When the user clicks "Copy to clipboard" button, I want to copy the description and the image to the clip board so they can paste it in word or excel...

When i try add both i get an error saying, Cannot convert image to type string, I've tried to convert the string to an object...but no can do...

Please Please Please help me!
0
Comment
Question by:skrombeen
  • 7
  • 6
  • 4
  • +3
22 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
0
 
LVL 1

Author Comment

by:skrombeen
Comment Utility
Hi

The link just shows how to add images into the clipboard, but does not show on how to solve my problem...

As said, I need to add an image and text simultaneously from 2 different locations into the clipboard...

Tx
Shaun
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Shaun,

I don't understand what you are looking for?  Are you looking to set multiple formats for the Clipboard?

Bob
0
 
LVL 1

Author Comment

by:skrombeen
Comment Utility
Hi

Yes, I would need to do that, I need to add an image & text into the clipboard
0
 
LVL 27

Expert Comment

by:Tolomir
Comment Utility
I don't think it's possible.

The clipboard can hold just one type of format: Text or Graphics.

Tolomir
0
 
LVL 1

Author Comment

by:skrombeen
Comment Utility
but if i copy this entire page into my clip board and paste it into word, it will give me the text & images?
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Also, what version of VB.NET do you have?  2005?

Bob
0
 
LVL 1

Author Comment

by:skrombeen
Comment Utility
Vb.net 2003
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Here is a 2003 example of multiple formats, but it won't work for pasting into Word or Excel:

    Dim data As New DataObject
    Dim bmp As New Bitmap(100, 100)
    Dim gr As Graphics = Graphics.FromImage(bmp)
    gr.Clear(Color.White)
    Dim rect As New Rectangle(0, 0, 100, 100)
    gr.FillRectangle(Brushes.AliceBlue, rect)
    rect.Inflate(-1, -1)
    gr.DrawRectangle(Pens.Red, rect)

    data.SetData(DataFormats.Text, "Test")
    data.SetData("System.Drawing.Bitmap", bmp)

    Clipboard.SetDataObject(data, True)

There are the formats present when you copy an image from Word:

? clipboard.GetDataObject.GetFormats
{Length=20}
    (0): "Object Descriptor"
    (1): "Rich Text Format"
    (2): "HTML Format"
    (3): "EnhancedMetafile"
    (4): "MetaFilePict"
    (5): "PNG"
    (6): "GIF"
    (7): "JFIF"
    (8): "PNG+Office Art"
    (9): "GIF+Office Art"
    (10): "JFIF+Office Art"
    (11): "Office Drawing Shape Format"
    (12): "ActiveClipboard"
    (13): "DeviceIndependentBitmap"
    (14): "System.Drawing.Bitmap"
    (15): "Bitmap"
    (16): "Embed Source"
    (17): "Link Source"
    (18): "Link Source Descriptor"
    (19): "ObjectLink"

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
These are the formats present when you copy an image + text in Word:

 clipboard.GetDataObject.GetFormats
{Length=12}
    (0): "Object Descriptor"
    (1): "Rich Text Format"
    (2): "HTML Format"
    (3): "System.String"
    (4): "UnicodeText"
    (5): "Text"
    (6): "EnhancedMetafile"
    (7): "MetaFilePict"
    (8): "Embed Source"
    (9): "Link Source"
    (10): "Link Source Descriptor"
    (11): "ObjectLink"

The System.Drawing.Bitmap is conspicuously missing.

Bob
0
 
LVL 1

Author Comment

by:skrombeen
Comment Utility
thanks...
but the main feature im going to need to to be able to copy & paste this into ms word/ms excel
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 37

Expert Comment

by:gregoryyoung
Comment Utility
  (1): "Rich Text Format"

supports both pictures and text ... so does html? I think its just a matter of formatting your data into one of these formats before you put it in the clip board.
0
 
LVL 1

Author Comment

by:skrombeen
Comment Utility
thanks, do you perhaps have a snippet of code? that could help me?
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
That was a great suggestion, Greg!!!

Here is some pseudo-code that might help with copying RichText to the clipboard:

1) Get an image
2) Copy it to the clipboard
3) Create a RichTextBox control
4) Append text to the RTB control
5) Paste the image into the RTB control
6) Copy the rich text from the RTB control to the clipboard in the RichText format.

Bob
0
 
LVL 37

Expert Comment

by:gregoryyoung
Comment Utility
Bob is right on. Using a hidden richtextbox will make this easy .. there are also libraries that can do this without needing a hidden control but if you are already using winforms this is probably not too big of a deal.

Cheers,

Greg
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
>> but if i copy this entire page into my clip board and paste it into word, it will give me the text & images?

Have you tried that?  
Word will grind away for quite a while, converting the HTML of this page into Word objects.  The result is rather unpleasant.

=-=-=-=-=-=-=-=-=-=-=-=-=-=
You can add both types of data to the clipboard, but programs will always grab one or the other when the end-user uses the paste command.

One option would be to render the text as graphics (say, in a white box that would appear beneath the image), then create a new image composed of the original image plus the "text-as-graphics" image below it.  

This would work, but it would depend on your ultimate goal whether it would do the job you need done.  For instance, if you expected the end-user to be able to later modify the text, it's no-go, but if you expect the user to just view or print the result, it would be fine.

If you expect the end user to be able to manipulate both the text and the graphics, then creating a combined object (say, an RTF or HTML document) as described above, would seem to be your only option.
0
 
LVL 37

Expert Comment

by:gregoryyoung
Comment Utility
Dan: I thought pasting RTF was pretty quick in word?
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
It is.

Bob
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
I read the comment "but if i copy this entire page... " as  referring to this web page on EE.
 
When I tried that, (Ctrl+A, Ctrl+C; switch to Word; Ctrl+V) Word behaved as I described.  WordPad seemed to malfunction.

Another thought:
It would be possible to create a Metafile document that includes both the image and the text and place that on the clipboard.  Perhaps Word / Excel could break out the image from the text.

We will need to know the ultimate purpose of this question in order to divine the best answer.

-- Dan
0
 
LVL 37

Expert Comment

by:gregoryyoung
Comment Utility
*gets a Y shaped stick*

its a chart!
0
 
LVL 1

Author Comment

by:skrombeen
Comment Utility
Dan: The purpose of this question is explained on the first question...

Basically what i have is a win form (vb.net),
On this form their is an image(logo) of a company and a description of the selected company...
Their is also a button labelled "Copy to clipboard"

When the user clicks this copy to clipboard button, the application should copy the selected text and then append the companies logo in the clipboard, so the user can paste this information into excel/word, as my client is currently putting a document together containing information and needs to know the source of these descriptions.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 500 total points
Comment Utility
So the purpose is to attach a logo image to the text.  You will expect the user to be able to modify the text but also immediately see your logo image embedded in the pasted text (and then probably delete it, i assume...).  I also now know that it is not just any graphic, but a specific image that will be added each time.

Thanks.  That clarifies things.

I agree that one solution might be to place both items into a separate RichEdit control then copy the entire content of that control to the clipboard.  The target app should know how to handle the combined data.

However...
I came across this interesting item:
    How To Add Custom Table to the Clipboard to be Pasted into Word
    http://support.microsoft.com/kb/q216676/

...which shows a step-by-step of pasting "create your own RTF data" into Word.  That presents an interesting possibility:

Create a small RTF file that contains your logo and the words "Hi there"  Read that file as text -- eg, into Notepad (not WordPad or Word.  It will look something like:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}
\viewkind4\uc1\pard\f0\fs20{\object\objemb{\*\objclass Paint.Picture}\objw1409\objh524{\*\objdata
01050000
02000000
07000000
50427275736800
00000000
00000000
20270000
424d0a2700000000000036000000280000005e000000230000000100180000000000d4260000c4
0e0000c40e00000000000000000000000000000000000000000000000000000000000000000000
... lots of lines removed...
f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7
f7f7f7f7f7f7ffffffffffffffffffffffffffffff0000030000000000
}}}\par
Hi there\par
}

(note the "Hi there" is right at the end).

Save that text as a resource.  When the user copies the text, read that resource, then replace the "Hi There" with the text that user has selected.  Then use the technique described in that article to put the data on the clipboard.  When the user Pastes it into Word, you will see exactly what you want to see.

-- Dan
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now