Graphics.AddMetafileComment(Byte[]) 메서드

정의

현재 Metafile에 주석을 추가합니다.Adds a comment to the current Metafile.

public:
 void AddMetafileComment(cli::array <System::Byte> ^ data);
public void AddMetafileComment (byte[] data);
member this.AddMetafileComment : byte[] -> unit
Public Sub AddMetafileComment (data As Byte())

매개 변수

data
Byte[]

주석을 포함한 바이트의 배열입니다.Array of bytes that contains the comment.

예제

다음 코드 예제는 Windows Forms와 함께 사용 하도록 설계 되었으며,이 PaintEventArgs e Paint thisForm Form 예제에 대 한 이벤트 처리기의 매개 변수인 및가 필요 합니다.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:

  • 임시 만듭니다 Graphics 메타 파일을 가져옵니다 작성용는 hdc, 해당 디바이스 컨텍스트에 대 한 핸들입니다.Creates a temporary Graphics for creating the metafile and gets an hdc, a handle to its device context.

  • 를 사용 하 여 새 메타 파일을 만듭니다 hdc .Creates a new metafile using the hdc.

  • Graphics에서 메타 파일을 표시 하기 위한를 만듭니다 Metafile .Creates a Graphics for display of the metafile from the Metafile.

  • 메타 파일에 사각형을 그립니다.Draws a rectangle to the metafile.

  • 메타 파일에 주석을 추가 합니다.Adds a comment to the metafile.

  • 메타 파일을 닫는 메타 파일을 삭제 합니다 Graphics .Disposes the Graphics for the metafile-which closes the metafile.

  • 메타 파일을 삭제 합니다.Disposes the metafile.

  • 임시를 해제 합니다 hdc .Releases the temporary hdc.

  • 임시을 삭제 Graphics 합니다.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;
   }
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'};
    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();
}
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"), _
    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

설명

이 메서드는이 Graphics 와 연결 된 경우에만 유효 Metafile 합니다.This method is valid only if this Graphics is associated with a Metafile.

적용 대상