Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1778
  • Last Modified:

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!
0
skrombeen
Asked:
skrombeen
  • 7
  • 6
  • 4
  • +3
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
0
 
skrombeenAuthor Commented:
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
 
Bob LearnedCommented:
Shaun,

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

Bob
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
skrombeenAuthor Commented:
Hi

Yes, I would need to do that, I need to add an image & text into the clipboard
0
 
TolomirAdministratorCommented:
I don't think it's possible.

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

Tolomir
0
 
skrombeenAuthor Commented:
but if i copy this entire page into my clip board and paste it into word, it will give me the text & images?
0
 
Bob LearnedCommented:
Also, what version of VB.NET do you have?  2005?

Bob
0
 
skrombeenAuthor Commented:
Vb.net 2003
0
 
Bob LearnedCommented:
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
 
Bob LearnedCommented:
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
 
skrombeenAuthor Commented:
thanks...
but the main feature im going to need to to be able to copy & paste this into ms word/ms excel
0
 
gregoryyoungCommented:
  (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
 
skrombeenAuthor Commented:
thanks, do you perhaps have a snippet of code? that could help me?
0
 
Bob LearnedCommented:
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
 
gregoryyoungCommented:
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
 
DanRollinsCommented:
>> 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
 
gregoryyoungCommented:
Dan: I thought pasting RTF was pretty quick in word?
0
 
Bob LearnedCommented:
It is.

Bob
0
 
DanRollinsCommented:
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
 
gregoryyoungCommented:
*gets a Y shaped stick*

its a chart!
0
 
skrombeenAuthor Commented:
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
 
DanRollinsCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 6
  • 4
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now