Graphics::AddMetafileComment Method (array<Byte>^)
Adds a comment to the current Metafile.
Assembly: System.Drawing (in System.Drawing.dll)
Parameters
- data
-
Type:
array<System::Byte>^
Array of bytes that contains the comment.
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: [SecurityPermission(SecurityAction::Demand, Flags = SecurityPermissionFlag::UnmanagedCode)] 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 = gcnew Metafile( "SampMeta.emf",hdc ); // Create graphics object to record metaFile. Graphics^ metaGraphics = Graphics::FromImage( metaFile1 ); // Draw rectangle in metaFile. metaGraphics->DrawRectangle( gcnew Pen( Color::Black,5.0f ), 0, 0, 100, 100 ); // Create comment and add to metaFile. array<Byte>^metaComment = {(Byte)'T',(Byte)'e',(Byte)'s',(Byte)'t'}; metaGraphics->AddMetafileComment( metaComment ); // Dispose of graphics object. delete metaGraphics; // Dispose of metafile. delete metaFile1; // Release handle to temporary device context. newGraphics->ReleaseHdc( hdc ); // Dispose of scratch graphics object. delete newGraphics; // Create existing metafile object to draw. Metafile^ metaFile2 = gcnew Metafile( "SampMeta.emf" ); // Draw metaFile to screen. e->Graphics->DrawImage( metaFile2, Point(0,0) ); // Dispose of metafile. delete metaFile2; }
Available since 1.1