How to Paste WMF from Clipboard

G

Guest

Hi group

I am using a 3rd party AX control in a VB.NET application. One of the methods of this control is to capture the current map within the control to the windows clipboard as .WMF. I am automating some precesses for the client and I don't know how to programmatically paste the WMF from the clipboard to another control in the application. The picture box control supports WMF but I don't know how to set its image property to whats in the clipboard

Here is my testing sample so far

<pre
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Clic
Me.AxMGMap1.copyMap() 'copy map to clipboard as WM
Dim iData As IDataObject = Clipboard.GetDataObject(
If iData.GetDataPresent(DataFormats.MetafilePict) Then 'is it WMF
Me.PictureBox1.Image = iData' Invalid Cast Here
Els
' No it is not
MsgBox("Could not retrieve data off the clipboard."
End I
End Su
</pre

iData is of type iDataObject, the picture box expects type Image - how to cast

Any help is appreciated

Scott
 
K

Ken Tucker [MVP]

Hi,

Copy MetaFile to clipboard
Clipboard.SetDataObject(Image.FromFile("C:\Test.wmf"))



Retrieve from clipboard
Dim iData As IDataObject = Clipboard.GetDataObject

If iData.GetDataPresent("System.Drawing.Imaging.Metafile") Then

Dim img As Image

img = CType(iData.GetData("System.Drawing.Imaging.Metafile"), Image)

PictureBox1.Image = img

Else

MessageBox.Show("Error getting data from clipboard")

End If



Ken
 
G

Guest

Hi Ken

Thanks for the code. I am still having an issue

This line
If iData.GetDataPresent("System.Drawing.Imaging.Metafile") The

always returns false, however when I look at the iData.getFormats this is returned

?iData.GetFormat
{Length=2
(0): "EnhancedMetafile
(1): "MetaFilePict

So I changed the code back to the original in the IF statement

If iData.GetDataPresent(DataFormats.MetafilePict) Then 'is it WMF
Dim img As Imag
img = CType(iData.GetData(DataFormats.EnhancedMetafile), Image
Me.PictureBox1.Image = im
Els
' No it is not
MsgBox("Could not retrieve data off the clipboard."
End I

However, no error is thrown for CType - but img is still 'nothing'. I've tried DataFormats.EnhancedMetafile and DataFormats.MetafilePict to no avail - img is always nothing. I also tried

img = CType(iData.GetData("System.Drawing.Imaging.Metafile"), Image

img = nothing

Any other thoughts

Thanks for your efforts

Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top