473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to Paste WMF from Clipboard

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
3 6669
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: tabonni | last post by:
Hello All I am creating an ASP page. There are a list of filename and checkbox next to it. When user checked all the documents they want and click ADD TO CLIPBOARD button. All filepaths will be...
3
by: Tor Inge Rislaa | last post by:
Copy, Cut and Paste How to code the Copy, Cut and Paste functionality in VB.NET. In VB 6.0 I used the following code: 'For Copy Clipboard.Clear Clipboard.SetText...
5
by: DraguVaso | last post by:
Hi, I'm looking for a way to Copy and Paste Files to the clipboard. I found a lot of articles to copy pieces of text and bitmaps etc, but nog whole files. Whay I need is like you have in...
3
by: Stilgar[bbs.isca.uiowa.edu] | last post by:
Here's my newbie question: I have several VB forms which are all inherit a standard template form that I made. In my template form, I added a menu bar with some generic cut, copy, and paste...
2
by: Keith | last post by:
I'm trying to come up with a way to create a contextmenu that will do all the "standard" functions (cut, copy, paste, undo, etc). There seems to be a lot of information out there - but nothing...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
4
by: Thom Little | last post by:
I have a form with three textboxes. In an external C# 2.0 application I need to load the clipboard with three pieces of information so I can position to the first textbox in the forma and select...
11
by: RobKinney1 | last post by:
Hello, I am looking for a clever way to prevent someone from pasting copied text outside of my app. I know how to monitor the clipboard and get an WM_DRAWCLIPBOARD message when text is stored...
17
by: Steve | last post by:
I'm trying to code cut, copy, and paste in vb 2005 so that when the user clicks on a toolbar button, the cut/copy/paste will work with whatever textbox the cursor is current located in (I have...
8
by: jh | last post by:
I'd like to copy/paste into a listbox during runtime. I can do this for a textbox but can't figure out how to accomplish this for a listbox. Any help? Thanks.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.