AddMetafileComment Method

Graphics.AddMetafileComment Method

Adds a comment to the current Metafile object.

[Visual Basic]
Public Sub AddMetafileComment( _
   ByVal data() As Byte _
)
[C#]
public void AddMetafileComment(
 byte[] data
);
[C++]
public: void AddMetafileComment(
 unsigned char data __gc[]
);
[JScript]
public function AddMetafileComment(
   data : Byte[]
);

Parameters

data
Array of bytes that contains the comment.

Return Value

This method does not return a value.

Remarks

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

Example

[Visual Basic, C#] The following 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 object for the example. The code performs the following actions:

  • Creates a temporary Graphics object for creating the metafile and gets an hdc, a handle to its device context.
  • Creates a new metafile using the hdc.
  • Creates a Graphics object for display of the metafile from the Metafile object.
  • Draws a rectangle to the metafile.
  • Adds a comment to the metafile.
  • Disposes the Graphics object for the metafile-which closes the metafile.
  • Disposes the metafile.
  • Releases the temporary hdc.
  • Disposes the temporary Graphics object.
  • Creates a second metafile from the previously created file.
  • Draws the metafile to the screen.
  • Disposes the metafile.
[Visual Basic] 
Public Sub AddMetafileCommentBytes(e As PaintEventArgs)
' Create temporary graphics object for metafile
' creation and get handle to its device context.
Dim newGraphics As Graphics = thisForm.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"), _
CByte("t")}
metaGraphics.AddMetafileComment(metaComment)
' Dispose of graphics object.
metaGraphics.Dispose()
' Dispose of metafile.
metaFile1.Dispose()
' Release handle to scratch device context.
newGraphics.ReleaseHdc(hdc)
' Dispose of scratch graphics object.
newGraphics.Dispose()
' 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.
metaFile2.Dispose()
End Sub
        
[C#] 
public void AddMetafileCommentBytes(PaintEventArgs e)
{
// Create temporary Graphics object for metafile
//  creation and get handle to its device context.
Graphics newGraphics = thisForm.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'};
metaGraphics.AddMetafileComment(metaComment);
// Dispose of graphics object.
metaGraphics.Dispose();
// Dispose of metafile.
metaFile1.Dispose();
// Release handle to temporary device context.
newGraphics.ReleaseHdc(hdc);
// Dispose of scratch graphics object.
newGraphics.Dispose();
// 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.
metaFile2.Dispose();
}
        

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Graphics Class | Graphics Members | System.Drawing Namespace

Show:
© 2016 Microsoft