PushLayer(Rect) Method

Summary

Adds the specified layer to the surface so that it receives all subsequent drawing operations until PopLayer is called.

Syntax
C#
VB
C++
public bool PushLayer( 
   Rect rect 
) 
  
Public Overloads Function PushLayer( _ 
   ByVal rect As Rect _ 
) As Boolean 
public: 
bool PushLayer(  
   Rect rect 
)  

Parameters

rect
The content rectangle mask for the layer.

Return Value

If this method succeeds, it returns true. Otherwise, it returns false.

Remarks

The PushLayer method allows a caller to begin redirecting drawing to a layer. All drawing operations are valid in a layer. The location of the layer is affected by the transform set on the surface.

Each PushLayer must have a matching PopLayer call. If there are more PopLayer calls than PushLayer calls, the EndDraw return false indicates that an error occurs.

Example
C#
VB
using Leadtools.Windows.D2DRendering; 
 
public void D2DSurfacePushLayerExample() 
{ 
   //Create a new instance of the D2DSurface object 
   D2DSurface d2dSurface = new D2DSurface(); 
 
   //Set the surface Size 
   d2dSurface.SurfaceSize = new Size(1000, 1000); 
 
   //Pass an empty rect to redraw the entire surface 
   d2dSurface.BeginDraw(Rect.Empty); 
 
   //Save the surface drawing state 
   D2DDrawingState drawingState = d2dSurface.Save(); 
 
   //Create an ellipse geometry 
   EllipseGeometry ellipse = new EllipseGeometry(); 
   ellipse.Center = new Point(500, 500); 
   ellipse.RadiusX = 100; 
   ellipse.RadiusY = 100; 
 
   GeometryGroup geometryGroup = new GeometryGroup(); 
   geometryGroup.Children.Add(ellipse); 
 
   //Push geometry to receive all subsequent drawing operations  
   d2dSurface.PushLayer(geometryGroup); 
 
   //Create a rect having the specified dimensions 
   Rect rect = new Rect(40, 40, 500, 200); 
 
   //Create a new instance of a brush from a new solid color brush 
   SolidColorBrush fill = new SolidColorBrush(Colors.Green); 
 
   //Clear the pushed Layer with the fill brush 
   d2dSurface.Clear(fill); 
 
   //Stop redirecting drawing operations to the layer 
   d2dSurface.PopLayer(); 
 
   //Restore the surface drawing state 
   d2dSurface.Restore(drawingState); 
 
   //End the Draw operation and invalidate the surface 
   d2dSurface.EndDraw(); 
 
   d2dSurface.Invalidate(Rect.Empty); 
} 
Imports Leadtools.Windows.D2DRendering 
 
 
Public Sub D2DSurfacePushLayerExample() 
   'Create a new instance of a D2DSurface 
   Dim d2dSurface As D2DSurface = New D2DSurface() 
 
   'Set the surface Size 
   d2dSurface.SurfaceSize = New Size(1000, 1000) 
 
   'Pass an empty rectangle to redraw the whole surface 
   d2dSurface.BeginDraw(System.Windows.Rect.Empty) 
 
   'Save the surface drawing state 
   Dim drawingState As D2DDrawingState = d2dSurface.Save() 
 
   'Create an ellipse geometry 
   Dim ellipse As EllipseGeometry = New EllipseGeometry() 
   ellipse.Center = New Point(500, 500) 
   ellipse.RadiusX = 100 
   ellipse.RadiusY = 100 
 
   Dim geomeTryGroup As GeometryGroup = New GeometryGroup() 
   geomeTryGroup.Children.Add(ellipse) 
 
   'Push the geometry object to receive all subsequent drawing operations  
   d2dSurface.PushLayer(geomeTryGroup) 
 
   'Create a rectangle having the specified dimensions 
   Dim rect As Rect = New Rect(40, 40, 500, 200) 
 
   'Create a new instance of a brush from a new solid color brush 
   Dim fill As SolidColorBrush = New SolidColorBrush(Colors.Green) 
 
   'Clear the pushed Layer with the fill brush 
   d2dSurface.Clear(fill) 
 
   'Stop redirecting drawing operations to the layer 
   d2dSurface.PopLayer() 
 
   'Restore the surface drawing state 
   d2dSurface.Restore(drawingState) 
 
   'End the Draw operation and invalidate the surface 
   d2dSurface.EndDraw() 
 
   d2dSurface.Invalidate(System.Windows.Rect.Empty) 
End Sub 

Requirements

Target Platforms

Help Version 21.0.2020.8.24
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Windows.D2DRendering Assembly