Copy paste to an image

Behavior in previous versions of the DSL Tools

In previous versions of the DslTools, when you wanted to export a selection to an image, or to the Clipboard, you had to write some custom code, or just take a screen copy of what you wanted.

 

New Behavior

From the VS2010 DSL SDK, the copy/paste as an image is available to all the new designers, and it’s easy to provide the feature for migrated existing designers.

How does the DSL author control this?

If you create a new graphical designer, you don’t need to do anything, the copy/paste is enabled by default.

 

If you migrated an existing designer, you can benefit from this new feature very simply:

  1. Having opened the DslDefinition.dsl, go to the DSL Explorer; in the Editor node, you’ll find a new property named “Enable Copy Paste”,
  2. Set “Enable Copy Paste” to CopyPasteOnly (the default is NoGeneratedCopyPaste in case of migrated designers, and CopyPasteOnly for new designers)
  3. Transform All Templates

image

What is the behavior for the DSL user?

The user will now be able to select the shapes and connectors he wants to copy, use the standard Copy (Ctrl+C) command, and paste the corresponding image to any application (for instance Paint or Word). The selection is copied in two different image formats:

  • bitmap (.bmp)
  • Enhanced Windows Metafile (.emf).

In most applications you can use the “Paste Special …” command to

Need More control?

There are a few extensions points related to this feature (namely in methods accessible from the ElementOperation property of the Diagram. They are beyond the scope of this blog entry, and will be the subject of a future post.