Graphics.AddMetafileComment Method (Byte())


Adds a comment to the current Metafile.

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

Public Sub AddMetafileComment (
	data As Byte()


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 PaintEventArgse, 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 Sub AddMetafileCommentBytes(ByVal e As PaintEventArgs)

    ' Create temporary graphics object for metafile
    ' creation and get handle to its device context.
    Dim newGraphics As Graphics = Me.CreateGraphics()
    Dim hdc As IntPtr = newGraphics.GetHdc()

    ' Create metafile object to record.
    Dim metaFile1 As New Metafile("SampMeta.emf", hdc)

    ' Create graphics object to record metaFile.
    Dim metaGraphics As Graphics = Graphics.FromImage(metaFile1)

    ' Draw rectangle in metaFile.
    metaGraphics.DrawRectangle(New Pen(Color.Black, 5), 0, 0, 100, 100)

    ' Create comment and add to metaFile.
    Dim metaComment As Byte() = {CByte("T"), CByte("e"), CByte("s"), _

    ' Dispose of graphics object.

    ' Dispose of metafile.

    ' Release handle to scratch device context.

    ' Dispose of scratch graphics object.

    ' Create existing metafile object to draw.
    Dim metaFile2 As New Metafile("SampMeta.emf")

    ' Draw metaFile to screen.
    e.Graphics.DrawImage(metaFile2, New Point(0, 0))

    ' Dispose of metafile.
End Sub

.NET Framework
Available since 1.1
Return to top