Graphics.AddMetafileComment(Byte[]) Graphics.AddMetafileComment(Byte[]) Graphics.AddMetafileComment(Byte[]) Graphics.AddMetafileComment(Byte[]) Method

定義

現在の 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 フォームで使用するように設計さPaintEventArgsれています。また、 Paintこの例では、 FormイベントthisFormハンドラーのパラメーターであるを必要eとしています。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ファイルを表示するためのを作成します。MetafileCreates 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.

  • 以前に作成したファイルから2番目のメタファイルを作成します。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.

適用対象