Clipboard issue. Can't get MetaFilePict data.

I am having an issue getting certain data off the clipboard in both Visual Basic 2003 and 2005 that wasn't an issue in VB6.

Here is how it works. We have a MapGuide ActiveX viewer control that AutoDesk uses to show autocad maps. They have a CopyMap function in this control that copies the map image to the clipboard.

In VB6 I can use the following line of code and get the image off the clipboard and place it in a picture control:

Clipboard.GetData(vbCFEMetafile)

In VB .Net however I am having an issue. After the CopyMap function is called, I do the following:

Dim lobjDataObjectAs IDataObject

Dim lobjImageAs Drawing.Image

lobjDataObject = Clipboard.GetDataObject()

lobjImage = lobjDataObject.GetData(DataFormats.MetafilePict)

While debugging, after the GetDataObject call, I check the return from the DataObjects GetFormats routine in the watch window. This tells me there is a MetaFilePict and and EnhancedMetaFile on the clipboard.

I can also go into an application like Paint or Word and paste the map image in those apps so I know for a fact the image is on the clipboard. The GetFormats indicates there is a metafilepict on the clipboard, yet the lobjDataObject.GetData(DataFormats.MetafilePict) returns an empty (Nothing) object. The watch window also displays a value of nothing if I place lobjDataObject.GetData(DataFormats.MetafilePict) as a watch value.

Just as a side note. I know the code above works because if I do a print screen and change the dataformat to Bitmap, I get a bitmap image back. I appear to just be having a problem with the type of data on the clipboard.

Can someone help me out on this problem.

[2581 byte] By [KevinRathgeber] at [2007-12-24]
# 1
Were you able to resolve the issue? I am encountering the same problem. Looks like I may have to do COM for this to work. Thanks!
RickyMendoza at 2007-8-31 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2
I hope this is not too late!
go to this site:
http://dobon.net/vb/dotnet/graphics/getclipboardmetafile.html

it has the solution;

Saeed

P.S.:it is a Japanese site,but the code is in English!

Saeedsad at 2007-8-31 > top of Msdn Tech,Windows Forms,Windows Forms General...