Name

Metafile

Synopsis

A metafile represents a set of records, each of which encapsulates a graphics operation.

There are a large number of different constructors, which allow you to construct a metafile from a file or stream (in Windows Enhanced Metafile File format), a system HDC (which can be obtained from a Graphics surface if necessary), or a Windows EMF handle. You can subsequently retrieve the EMF handle (for interop) with the GetHenhmetafile() method. Many of the methods also allow you to specify a rectangle that positions the metafile on the page, along with the units that define that rectangle (see MetafileFrameUnit).

You can retrieve the MetafileHeader with the GetMetafileHeader() method.

While you can use the System.Drawing.Graphics.DrawImage() method to paint the metafile, you can play an individual record with the PlayRecord() method. See EmfPlusRecordType for information about EMF records.

To record a metafile, you should create a reference System.Drawing.Graphics surface, and then use the System.Drawing.Graphics.GetHdc() to lock its Win32 HDC. You can then pass this as the reference HDC in an appropriate constructor for your Metafile object. You can then use the System.Drawing.Graphics.FromImage() method to get a graphics surface for the metafile. Everything you then draw on the surface will be recorded on the metafile. If you specified a filename or stream in the Metafile constructor, the image will automatically be stored, or you can call the Save() method. You should ...

Get .NET Windows Forms in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.