Not
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
Om du hanterar din egen buffrade grafik måste du kunna skapa och återge grafikbuffertar. Du kan skapa instanser av klassen BufferedGraphics som är associerad med ritningsytor på skärmen genom att anropa metoden Allocate. Den här metoden skapar en BufferedGraphics-instans som är associerad med en viss återgivningsyta, till exempel ett formulär eller en kontroll. När du har skapat en BufferedGraphics instans kan du rita grafik till bufferten som den representerar via egenskapen Graphics. När du har utfört alla grafikåtgärder kan du kopiera innehållet i bufferten till skärmen genom att anropa metoden Render.
Anmärkning
Om du utför din egen rendering ökar minnesförbrukningen, även om ökningen kanske bara är liten.
Så här visar du buffrad grafik manuellt
Hämta en referens till en instans av klassen BufferedGraphicsContext. Mer information finns i Så här: Hantera buffrad grafik manuellt.
Skapa en instans av klassen BufferedGraphics genom att anropa metoden Allocate, enligt följande kodexempel.
// This example assumes the existence of a form called Form1. BufferedGraphicsContext currentContext; BufferedGraphics myBuffer; // Gets a reference to the current BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current; // Creates a BufferedGraphics instance associated with Form1, and with // dimensions the same size as the drawing surface of Form1. myBuffer = currentContext.Allocate(this.CreateGraphics(), this.DisplayRectangle);' This example assumes the existence of a form called Form1. Dim currentContext As BufferedGraphicsContext Dim myBuffer As BufferedGraphics ' Gets a reference to the current BufferedGraphicsContext. currentContext = BufferedGraphicsManager.Current ' Creates a BufferedGraphics instance associated with Form1, and with ' dimensions the same size as the drawing surface of Form1. myBuffer = currentContext.Allocate(Me.CreateGraphics, _ Me.DisplayRectangle)Rita grafik till grafikbufferten genom att ange egenskapen Graphics. Till exempel:
// Draws an ellipse to the graphics buffer. myBuffer.Graphics.DrawEllipse(Pens.Blue, this.DisplayRectangle);' Draws an ellipse to the graphics buffer. myBuffer.Graphics.DrawEllipse(Pens.Blue, Me.DisplayRectangle)När du har slutfört alla ritningsåtgärder till grafikbufferten anropar du metoden Render för att återge bufferten, antingen till den rityta som är associerad med bufferten eller till en angiven rityta, som du ser i följande kodexempel.
// This example assumes the existence of a BufferedGraphics instance // called myBuffer. // Renders the contents of the buffer to the drawing surface associated // with the buffer. myBuffer.Render(); // Renders the contents of the buffer to the specified drawing surface. myBuffer.Render(this.CreateGraphics());' Renders the contents of the buffer to the drawing surface associated ' with the buffer. myBuffer.Render() ' Renders the contents of the buffer to the specified drawing surface. myBuffer.Render(Me.CreateGraphics)När du är klar med återgivningen av grafik anropar du metoden
Disposepå den BufferedGraphics instansen för att frigöra systemresurser.myBuffer.Dispose();myBuffer.Dispose()
Se även
.NET Desktop feedback