This documentation is archived and is not being maintained.

Graphics.AddMetafileComment Method

Adds a comment to the current Metafile.

Namespace:  System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)

public void AddMetafileComment(
	byte[] data


Type: System.Byte[]
Array of bytes that contains the comment.

This method is valid only if this Graphics is associated with a Metafile.

The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler, as well as thisForm, the Form for the example. The code performs the following actions:

  • Creates a temporary Graphics for creating the metafile and gets an hdc, a handle to its device context.

  • Creates a new metafile using the hdc.

  • Creates a Graphics for display of the metafile from the Metafile.

  • Draws a rectangle to the metafile.

  • Adds a comment to the metafile.

  • Disposes the Graphics for the metafile-which closes the metafile.

  • Disposes the metafile.

  • Releases the temporary hdc.

  • Disposes the temporary Graphics.

  • Creates a second metafile from the previously created file.

  • Draws the metafile to the screen.

  • Disposes the metafile.

private void AddMetafileCommentBytes(PaintEventArgs e)
    // Create temporary Graphics object for metafile
    //  creation and get handle to its device context.
    Graphics newGraphics = this.CreateGraphics();
    IntPtr hdc = newGraphics.GetHdc();

    // Create metafile object to record.
    Metafile metaFile1 = new Metafile("SampMeta.emf", hdc);

    // Create graphics object to record metaFile.
    Graphics metaGraphics = Graphics.FromImage(metaFile1);

    // Draw rectangle in metaFile.
    metaGraphics.DrawRectangle(new Pen(Color.Black, 5), 0, 0, 100, 100);

    // Create comment and add to metaFile.
    byte[] metaComment = {(byte)'T', (byte)'e', (byte)'s', (byte)'t'};

    // Dispose of graphics object.

    // Dispose of metafile.

    // Release handle to temporary device context.

    // Dispose of scratch graphics object.

    // Create existing metafile object to draw.
    Metafile metaFile2 = new Metafile("SampMeta.emf");

    // Draw metaFile to screen.
    e.Graphics.DrawImage(metaFile2, new Point(0, 0));

    // Dispose of metafile.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.