By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,905 Members | 1,626 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,905 IT Pros & Developers. It's quick & easy.

How to Paste WMF from Clipboard

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

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

Retrieve from clipboard
Dim iData As IDataObject = Clipboard.GetDataObject

If iData.GetDataPresent("System.Drawing.Imaging.Metaf ile") Then

Dim img As Image

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

PictureBox1.Image = img

Else

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

End If

Ken
-------------------
"Scott Friedrich" <an*******@discussions.microsoft.com> wrote in message
news:1E**********************************@microsof t.com...
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.Click
Me.AxMGMap1.copyMap() 'copy map to clipboard as WMF
Dim iData As IDataObject = Clipboard.GetDataObject()
If iData.GetDataPresent(DataFormats.MetafilePict) Then 'is it WMF?
Me.PictureBox1.Image = iData' Invalid Cast Here!
Else
' No it is not.
MsgBox("Could not retrieve data off the clipboard.")
End If
End Sub
</pre>

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

Any help is appreciated,

Scott

Nov 20 '05 #2

P: n/a
Hi Ken

Thanks for the code. I am still having an issue

This line
If iData.GetDataPresent("System.Drawing.Imaging.Metaf ile") 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.Metafi le"), Image

img = nothing

Any other thoughts

Thanks for your efforts

Scott
Nov 20 '05 #3

P: n/a
Hi,

Maybe this will work
Dim mfData As System.Drawing.Imaging.Metafile

mfData =
CType(iData.GetData(DataFormats.EnhancedMetafile), System.Drawing.Imaging.Metafile)

PictureBox1.Image = mfData

Ken

------------------

"Scott Friedrich" <an*******@discussions.microsoft.com> wrote in message
news:D9**********************************@microsof t.com...
Hi Ken,

Thanks for the code. I am still having an issue.

This line:
If iData.GetDataPresent("System.Drawing.Imaging.Metaf ile") Then

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

?iData.GetFormats
{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 Image
img = CType(iData.GetData(DataFormats.EnhancedMetafile), Image)
Me.PictureBox1.Image = img
Else
' No it is not.
MsgBox("Could not retrieve data off the clipboard.")
End If

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.Metafi le"), Image)

img = nothing.

Any other thoughts?

Thanks for your efforts,

Scott

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.