Graphics.AddMetafileComment(Byte[]) Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Dodaje komentarz do bieżącego Metafileelementu .
public:
void AddMetafileComment(cli::array <System::Byte> ^ data);
public void AddMetafileComment (byte[] data);
member this.AddMetafileComment : byte[] -> unit
Public Sub AddMetafileComment (data As Byte())
Parametry
- data
- Byte[]
Tablica bajtów zawierająca komentarz.
Przykłady
Poniższy przykład kodu jest przeznaczony do użycia z Windows Forms i wymaga PaintEventArgse
parametru Paint programu obsługi zdarzeń, a także thisForm
Form parametru przykładu . Kod wykonuje następujące akcje:
Tworzy tymczasowe Graphics narzędzie do tworzenia metapliku i pobiera
hdc
uchwyt do kontekstu urządzenia.Tworzy nowy metaplik przy użyciu polecenia
hdc
.Tworzy element Graphics do wyświetlania metapliku z pliku Metafile.
Rysuje prostokąt do metapliku.
Dodaje komentarz do metapliku.
Graphics Usuwa element metapliku, który zamyka metaplik.
Usuwa metaplik.
Zwalnia tymczasowy
hdc
element .Usuwa tymczasowy Graphicselement .
Tworzy drugi metaplik z wcześniej utworzonego pliku.
Rysuje metaplik na ekran.
Usuwa metaplik.
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
Uwagi
Ta metoda jest prawidłowa tylko wtedy, gdy jest ona Graphics skojarzona z elementem Metafile.
Dotyczy
Opinia
https://aka.ms/ContentUserFeedback.
Dostępne już wkrótce: W 2024 r. będziemy stopniowo wycofywać zgłoszenia z serwisu GitHub jako mechanizm przesyłania opinii na temat zawartości i zastępować go nowym systemem opinii. Aby uzyskać więcej informacji, sprawdź:Prześlij i wyświetl opinię dla