skrombeen
asked on
Adding an image & text into the clipboard
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!
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!
ASKER
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
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
Shaun,
I don't understand what you are looking for? Are you looking to set multiple formats for the Clipboard?
Bob
I don't understand what you are looking for? Are you looking to set multiple formats for the Clipboard?
Bob
ASKER
Hi
Yes, I would need to do that, I need to add an image & text into the clipboard
Yes, I would need to do that, I need to add an image & text into the clipboard
I don't think it's possible.
The clipboard can hold just one type of format: Text or Graphics.
Tolomir
The clipboard can hold just one type of format: Text or Graphics.
Tolomir
ASKER
but if i copy this entire page into my clip board and paste it into word, it will give me the text & images?
Also, what version of VB.NET do you have? 2005?
Bob
Bob
ASKER
Vb.net 2003
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.A liceBlue, rect)
rect.Inflate(-1, -1)
gr.DrawRectangle(Pens.Red, rect)
data.SetData(DataFormats.T ext, "Test")
data.SetData("System.Drawi ng.Bitmap" , bmp)
Clipboard.SetDataObject(da ta, True)
There are the formats present when you copy an image from Word:
? clipboard.GetDataObject.Ge tFormats
{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
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.A
rect.Inflate(-1, -1)
gr.DrawRectangle(Pens.Red,
data.SetData(DataFormats.T
data.SetData("System.Drawi
Clipboard.SetDataObject(da
There are the formats present when you copy an image from Word:
? clipboard.GetDataObject.Ge
{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
These are the formats present when you copy an image + text in Word:
clipboard.GetDataObject.Ge tFormats
{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
clipboard.GetDataObject.Ge
{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
ASKER
thanks...
but the main feature im going to need to to be able to copy & paste this into ms word/ms excel
but the main feature im going to need to to be able to copy & paste this into ms word/ms excel
(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.
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.
ASKER
thanks, do you perhaps have a snippet of code? that could help me?
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
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
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
Cheers,
Greg
>> 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.
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.
Dan: I thought pasting RTF was pretty quick in word?
It is.
Bob
Bob
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
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
*gets a Y shaped stick*
its a chart!
its a chart!
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.kdkeys.net/forums/704/ShowPost.aspx