Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can I tell if clipboard contents can be pasted as Enhanced Metafile

Posted on 2007-12-01
4
Medium Priority
?
248 Views
Last Modified: 2012-05-05
I am developing an add-in for Word in VB.NET. One of the functions is to Paste clipboard contents as an Enhanced Metafile (my company frequently copy charts and tables from Excel to Word in this format).

I would like to test that the contents of the clipboard can be pasted as enhanced metafile. Currently I just trap the error if it cannot but if I can find out in advance I can then disable the menu item (or change its name) to be clearer to the user.

Code for this test would be much appreciated.
0
Comment
Question by:CarlPritchard
  • 2
4 Comments
 
LVL 10

Expert Comment

by:athapa
ID: 20389242
Use ClipBoard.GetDataPresent to figure out if the format you want is available in the clipboard. You can also enumerate all of the formats available in the clipboard.

HTH,
AT
0
 
LVL 6

Author Comment

by:CarlPritchard
ID: 20389333
Please could you give a code example that shows if there is data that can be pasted as enhanced metafile (ie is compatible data) including any required namespaces/imports.
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 1000 total points
ID: 20389501
Hi CarlPritchard;

Here is sample code to show you how to see if the clipboard has the correct data. No special imports needed.

Fernando
        If Clipboard.ContainsData(DataFormats.EnhancedMetafile) Then
            ' Then the Clipboard contains data in the EnhancedMetafile format
        Else
            ' The Clipboard DOES NOT contain data in the EnhancedMetafile
        End If

Open in new window

0
 
LVL 10

Expert Comment

by:athapa
ID: 20389509
the only required name space is
System.Windows.Form
which should be already there if your app is windows form app.

imports System.Windows.Form

Private Const FormatName As String = "EnhancedMetafile" 'Enhanced Meta-File Picture

'Call this function anytime you want to see if EnhancedMetaFile is in the clipboard
Private Function IsEnhancedMetaAvailableInClipboard() As Boolean
        Dim clip As IDataObject = Clipboard.GetDataObject()
        Dim AvailableFormats As String() = clip.GetFormats()

        Return (System.Array.IndexOf(AvailableFormats, FormatName) > -1)

End Function

I used the following test code to figure out what other formats are available in clipboard as well as to test the function above

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Debug.WriteLine(IsEnhancedMetaAvailableInClipboard())

        For Each ClipboardFormat As String In Clipboard.GetDataObject().GetFormats()
            System.Diagnostics.Debug.WriteLine(ClipboardFormat)
        Next

    End Sub
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month11 days, 15 hours left to enroll

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question