次の方法で共有


Graphics.AddMetafileComment メソッド

現在の Metafile オブジェクトにコメントを追加します。

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

パラメータ

  • data
    コメントが含まれているバイトの配列。

戻り値

このメソッドは値を返しません。

解説

このメソッドは、この Graphics オブジェクトが Metafile オブジェクトに関連付けられている場合にだけ有効です。

使用例

[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 Paint イベント ハンドラのパラメータである PaintEventArgs e と、 Form オブジェクトの例である thisForm が必要です。このコードは次のアクションを実行します。

  • メタファイル作成用の一時 Graphics オブジェクトを作成し、そのデバイス コンテキストを識別するハンドル hdc を取得します。
  • hdc を使用して、新しいメタファイルを作成します。
  • Metafile オブジェクトから、メタファイルの表示に使用する Graphics オブジェクトを作成します。
  • メタファイルに四角形を描画します。
  • メタファイルにコメントを追加します。
  • メタファイルの Graphics オブジェクトを破棄します。そのメタファイルは閉じられます。
  • メタファイルを破棄します。
  • 一時 hdc を解放します。
  • 一時 Graphics オブジェクトを破棄します。
  • 以前に作成されたファイルから 2 番目のメタファイルを作成します。
  • 画面にメタファイルを描画します。
  • メタファイルを破棄します。
 
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] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

Graphics クラス | Graphics メンバ | System.Drawing 名前空間