Can I copy and paste images from MS Office applications onto the Diagram?
(Views :1120)

Essential Diagram does not have pre-built support for interfacing with clipboard copy/paste from the MS Office applications. The Diagram copy/paste implementation is confined to 'Node' type drawing objects that are native to Essential Diagram. To copy/paste an image, the Clipboard's data object should be an instance of the Diagram.ClipboardNodeCollection type populated with a Diagram.BitmapNode or a Diagram.MetafileNode that wraps the image. Since .NET uses its own format that is not compatible with the EnhancedMetafile format, you will have to use reflection to achieve this feature of copying and pasting images from MS Office applications like Excel, PowerPoint, Word, or Visio.

The sample provided in this Knowledge Base article demonstrates how you can add support to your Essential Diagram application to allow copy/paste from MS Office.

[C#]

using System.Runtime.InteropServices;
using System.Reflection;


public const uint CF_METAFILEPICT = 3;
public const uint CF_ENHMETAFILE = 14;

[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern bool OpenClipboard(IntPtr hWndNewOwner);

[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern bool CloseClipboard();

[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern IntPtr GetClipboardData(uint format);

[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern bool IsClipboardFormatAvailable(uint format);

 

//Handle EnhancedMetafile format from the clipboard and insert MetafileNode
if (clipboardData.GetDataPresent(DataFormats.EnhancedMetafile))
{
if (OpenClipboard(this.Handle))

{
 if (IsClipboardFormatAvailable(CF_ENHMETAFILE))
 {
 
  IntPtr ptr = GetClipboardData(CF_ENHMETAFILE);
  if (!ptr.Equals(new IntPtr(0)))
  {
   Metafile metafile = new Metafile(ptr,true);

   MetafileNode mfnode = new MetafileNode(metafile);
   InsertNodesCmd insmfCmd = new InsertNodesCmd();
   insmfCmd.Nodes.Add(mfnode);   
   this.diagram1.ExecuteCommand(insmfCmd);
    
  }
 }
 CloseClipboard();
}

::adCenter::