Graphics.AddMetafileComment 方法
向当前 Metafile 添加注释。
**命名空间:**System.Drawing
**程序集:**System.Drawing(在 system.drawing.dll 中)
语法
声明
Public Sub AddMetafileComment ( _
data As Byte() _
)
用法
Dim instance As Graphics
Dim data As Byte()
instance.AddMetafileComment(data)
public void AddMetafileComment (
byte[] data
)
public:
void AddMetafileComment (
array<unsigned char>^ data
)
public void AddMetafileComment (
byte[] data
)
public function AddMetafileComment (
data : byte[]
)
参数
- data
包含注释的字节的数组。
备注
只有当此 Graphics 与 Metafile 关联时,此方法才有效。
示例
下面的代码示例设计为与 Windows 窗体一起使用,它需要 PaintEventArgse(这是 Paint 事件处理程序的参数)及 thisForm(该示例的 Form)。代码执行下列操作:
创建用于创建图元文件的临时 Graphics,并获取 hdc,其设备上下文的句柄。
使用 hdc 创建新图元文件。
创建 Graphics,用于显示 Metafile 的图元文件。
将矩形绘制图元文件中。
向图元文件中添加注释。
释放图元文件的 Graphics,该对象关闭图元文件。
释放图元文件。
释放临时 hdc。
释放临时 Graphics。
从以前创建的文件创建第二个图元文件。
将图元文件绘制到屏幕。
释放图元文件。
Public 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
public 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();
}
public:
[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;
}
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0