Graphics.SetClip Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
SetClip(Region, CombineMode) |
Sets the clipping region of this Graphics to the result of the specified operation combining the current clip region and the specified Region. |
SetClip(RectangleF, CombineMode) |
Sets the clipping region of this Graphics to the result of the specified operation combining the current clip region and the rectangle specified by a RectangleF structure. |
SetClip(Rectangle, CombineMode) |
Sets the clipping region of this Graphics to the result of the specified operation combining the current clip region and the rectangle specified by a Rectangle structure. |
SetClip(Graphics, CombineMode) |
Sets the clipping region of this Graphics to the result of the specified combining operation of the current clip region and the Clip property of the specified Graphics. |
SetClip(GraphicsPath, CombineMode) |
Sets the clipping region of this Graphics to the result of the specified operation combining the current clip region and the specified GraphicsPath. |
SetClip(RectangleF) |
Sets the clipping region of this Graphics to the rectangle specified by a RectangleF structure. |
SetClip(Rectangle) |
Sets the clipping region of this Graphics to the rectangle specified by a Rectangle structure. |
SetClip(Graphics) |
Sets the clipping region of this Graphics to the |
SetClip(GraphicsPath) |
Sets the clipping region of this Graphics to the specified GraphicsPath. |
SetClip(Region, CombineMode)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
public:
void SetClip(System::Drawing::Region ^ region, System::Drawing::Drawing2D::CombineMode combineMode);
public void SetClip (System.Drawing.Region region, System.Drawing.Drawing2D.CombineMode combineMode);
member this.SetClip : System.Drawing.Region * System.Drawing.Drawing2D.CombineMode -> unit
Public Sub SetClip (region As Region, combineMode As CombineMode)
Parameters
- combineMode
- CombineMode
Member from the CombineMode enumeration that specifies the combining operation to use.
Examples
The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e
, which is a parameter of the Paint event handler. The code performs the following actions:
Creates a small rectangle for the clipping region.
Sets the clipping region to the rectangle with the Replace member.
Fills a large rectangle with a solid black brush.
The result is a small, filled, black rectangle.
public:
void SetClipRegionCombine( PaintEventArgs^ e )
{
// Create region for clipping.
System::Drawing::Region^ clipRegion = gcnew System::Drawing::Region( Rectangle(0,0,100,100) );
// Set clipping region of graphics to region.
e->Graphics->SetClip( clipRegion, CombineMode::Replace );
// Fill rectangle to demonstrate clip region.
e->Graphics->FillRectangle( gcnew SolidBrush( Color::Black ), 0, 0, 500, 300 );
}
private void SetClipRegionCombine(PaintEventArgs e)
{
// Create region for clipping.
Region clipRegion = new Region(new Rectangle(0, 0, 100, 100));
// Set clipping region of graphics to region.
e.Graphics.SetClip(clipRegion, CombineMode.Replace);
// Fill rectangle to demonstrate clip region.
e.Graphics.FillRectangle(new SolidBrush(Color.Black), 0, 0, 500, 300);
}
Private Sub SetClipRegionCombine(ByVal e As PaintEventArgs)
' Create region for clipping.
Dim clipRegion As New [Region](New Rectangle(0, 0, 100, 100))
' Set clipping region of graphics to region.
e.Graphics.SetClip(clipRegion, CombineMode.Replace)
' Fill rectangle to demonstrate clip region.
e.Graphics.FillRectangle(New SolidBrush(Color.Black), 0, 0, _
500, 300)
End Sub
Applies to
SetClip(RectangleF, CombineMode)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
Sets the clipping region of this Graphics to the result of the specified operation combining the current clip region and the rectangle specified by a RectangleF structure.
public:
void SetClip(System::Drawing::RectangleF rect, System::Drawing::Drawing2D::CombineMode combineMode);
public void SetClip (System.Drawing.RectangleF rect, System.Drawing.Drawing2D.CombineMode combineMode);
member this.SetClip : System.Drawing.RectangleF * System.Drawing.Drawing2D.CombineMode -> unit
Public Sub SetClip (rect As RectangleF, combineMode As CombineMode)
Parameters
- rect
- RectangleF
RectangleF structure to combine.
- combineMode
- CombineMode
Member of the CombineMode enumeration that specifies the combining operation to use.
Examples
The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e
, which is a parameter of the Paint event handler. The code performs the following actions:
Creates a small rectangle for the clipping region.
Sets the clipping region to the rectangle with the Replace member.
Fills a large rectangle with a solid black brush.
The result is a small, filled, black rectangle.
public:
void SetClipRectangleFCombine( PaintEventArgs^ e )
{
// Create rectangle for clipping region.
RectangleF clipRect = RectangleF(0.0F,0.0F,100.0F,100.0F);
// Set clipping region of graphics to rectangle.
e->Graphics->SetClip( clipRect, CombineMode::Replace );
// Fill rectangle to demonstrate clip region.
e->Graphics->FillRectangle( gcnew SolidBrush( Color::Black ), 0, 0, 500, 300 );
}
private void SetClipRectangleFCombine(PaintEventArgs e)
{
// Create rectangle for clipping region.
RectangleF clipRect = new RectangleF(0.0F, 0.0F, 100.0F, 100.0F);
// Set clipping region of graphics to rectangle.
e.Graphics.SetClip(clipRect, CombineMode.Replace);
// Fill rectangle to demonstrate clip region.
e.Graphics.FillRectangle(new SolidBrush(Color.Black), 0, 0, 500, 300);
}
Private Sub SetClipRectangleFCombine(ByVal e As PaintEventArgs)
' Create rectangle for clipping region.
Dim clipRect As New RectangleF(0.0F, 0.0F, 100.0F, 100.0F)
' Set clipping region of graphics to rectangle.
e.Graphics.SetClip(clipRect, CombineMode.Replace)
' Fill rectangle to demonstrate clip region.
e.Graphics.FillRectangle(New SolidBrush(Color.Black), 0, 0, _
500, 300)
End Sub
Applies to
SetClip(Rectangle, CombineMode)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
public:
void SetClip(System::Drawing::Rectangle rect, System::Drawing::Drawing2D::CombineMode combineMode);
public void SetClip (System.Drawing.Rectangle rect, System.Drawing.Drawing2D.CombineMode combineMode);
member this.SetClip : System.Drawing.Rectangle * System.Drawing.Drawing2D.CombineMode -> unit
Public Sub SetClip (rect As Rectangle, combineMode As CombineMode)
Parameters
- combineMode
- CombineMode
Member of the CombineMode enumeration that specifies the combining operation to use.
Examples
The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e
, which is a parameter of the Paint event handler. The code performs the following actions:
Creates a small rectangle for the clipping region.
Sets the clipping region to the rectangle with the Replace member.
Fills a large rectangle with a solid black brush.
The result is a small, filled, black rectangle.
public:
void SetClipRectangleCombine( PaintEventArgs^ e )
{
// Create rectangle for clipping region.
Rectangle clipRect = Rectangle(0,0,100,100);
// Set clipping region of graphics to rectangle.
e->Graphics->SetClip( clipRect, CombineMode::Replace );
// Fill rectangle to demonstrate clip region.
e->Graphics->FillRectangle( gcnew SolidBrush( Color::Black ), 0, 0, 500, 300 );
}
private void SetClipRectangleCombine(PaintEventArgs e)
{
// Create rectangle for clipping region.
Rectangle clipRect = new Rectangle(0, 0, 100, 100);
// Set clipping region of graphics to rectangle.
e.Graphics.SetClip(clipRect, CombineMode.Replace);
// Fill rectangle to demonstrate clip region.
e.Graphics.FillRectangle(new SolidBrush(Color.Black), 0, 0, 500, 300);
}
Private Sub SetClipRectangleCombine(ByVal e As PaintEventArgs)
' Create rectangle for clipping region.
Dim clipRect As New Rectangle(0, 0, 100, 100)
' Set clipping region of graphics to rectangle.
e.Graphics.SetClip(clipRect, CombineMode.Replace)
' Fill rectangle to demonstrate clip region.
e.Graphics.FillRectangle(New SolidBrush(Color.Black), 0, 0, _
500, 300)
End Sub
Applies to
SetClip(Graphics, CombineMode)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
public:
void SetClip(System::Drawing::Graphics ^ g, System::Drawing::Drawing2D::CombineMode combineMode);
public void SetClip (System.Drawing.Graphics g, System.Drawing.Drawing2D.CombineMode combineMode);
member this.SetClip : System.Drawing.Graphics * System.Drawing.Drawing2D.CombineMode -> unit
Public Sub SetClip (g As Graphics, combineMode As CombineMode)
Parameters
- combineMode
- CombineMode
Member of the CombineMode enumeration that specifies the combining operation to use.
Examples
The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e
, which is a parameter of the Paint event handler, as well as thisForm
, the Form for the example. The code performs the following actions:
Creates a temporary Graphics from the
thisForm
Form of the example.Sets the clipping region of the temporary Graphics to a small square.
Updates the clipping region of the form's graphic object to that of the new Graphics with the Replace member.
Fills a large rectangle with a solid black brush.
The result is a small, filled, black square.
public:
void SetClipGraphicsCombine( PaintEventArgs^ e )
{
// Create temporary graphics object and set its clipping region.
Graphics^ newGraphics = this->CreateGraphics();
newGraphics->SetClip( Rectangle(0,0,100,100) );
// Update clipping region of graphics to clipping region of new
// graphics.
e->Graphics->SetClip( newGraphics, CombineMode::Replace );
// Fill rectangle to demonstrate clip region.
e->Graphics->FillRectangle( gcnew SolidBrush( Color::Black ), 0, 0, 500, 300 );
// Release new graphics.
delete newGraphics;
}
private void SetClipGraphicsCombine(PaintEventArgs e)
{
// Create temporary graphics object and set its clipping region.
Graphics newGraphics = this.CreateGraphics();
newGraphics.SetClip(new Rectangle(0, 0, 100, 100));
// Update clipping region of graphics to clipping region of new
// graphics.
e.Graphics.SetClip(newGraphics, CombineMode.Replace);
// Fill rectangle to demonstrate clip region.
e.Graphics.FillRectangle(new SolidBrush(Color.Black), 0, 0, 500, 300);
// Release new graphics.
newGraphics.Dispose();
}
Private Sub SetClipGraphicsCombine(ByVal e As PaintEventArgs)
' Create temporary graphics object and set its clipping region.
Dim newGraphics As Graphics = Me.CreateGraphics()
newGraphics.SetClip(New Rectangle(0, 0, 100, 100))
' Update clipping region of graphics to clipping region of new
' graphics.
e.Graphics.SetClip(newGraphics, CombineMode.Replace)
' Fill rectangle to demonstrate clip region.
e.Graphics.FillRectangle(New SolidBrush(Color.Black), 0, 0, _
500, 300)
' Release new graphics.
newGraphics.Dispose()
End Sub
Applies to
SetClip(GraphicsPath, CombineMode)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
Sets the clipping region of this Graphics to the result of the specified operation combining the current clip region and the specified GraphicsPath.
public:
void SetClip(System::Drawing::Drawing2D::GraphicsPath ^ path, System::Drawing::Drawing2D::CombineMode combineMode);
public void SetClip (System.Drawing.Drawing2D.GraphicsPath path, System.Drawing.Drawing2D.CombineMode combineMode);
member this.SetClip : System.Drawing.Drawing2D.GraphicsPath * System.Drawing.Drawing2D.CombineMode -> unit
Public Sub SetClip (path As GraphicsPath, combineMode As CombineMode)
Parameters
- path
- GraphicsPath
GraphicsPath to combine.
- combineMode
- CombineMode
Member of the CombineMode enumeration that specifies the combining operation to use.
Examples
The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e
, which is a parameter of the Paint event handler. The code performs the following actions:
Creates a graphics path and adds an ellipse to the path.
Sets the clipping region to the elliptical path with the Replace member.
Fills a large rectangle with a solid black brush.
The result is a filled, black ellipse.
public:
void SetClipPathCombine( PaintEventArgs^ e )
{
// Create graphics path.
GraphicsPath^ clipPath = gcnew GraphicsPath;
clipPath->AddEllipse( 0, 0, 200, 100 );
// Set clipping region to path.
e->Graphics->SetClip( clipPath, CombineMode::Replace );
// Fill rectangle to demonstrate clipping region.
e->Graphics->FillRectangle( gcnew SolidBrush( Color::Black ), 0, 0, 500, 300 );
}
private void SetClipPathCombine(PaintEventArgs e)
{
// Create graphics path.
GraphicsPath clipPath = new GraphicsPath();
clipPath.AddEllipse(0, 0, 200, 100);
// Set clipping region to path.
e.Graphics.SetClip(clipPath, CombineMode.Replace);
// Fill rectangle to demonstrate clipping region.
e.Graphics.FillRectangle(new SolidBrush(Color.Black), 0, 0, 500, 300);
}
Private Sub SetClipPathCombine(ByVal e As PaintEventArgs)
' Create graphics path.
Dim clipPath As New GraphicsPath
clipPath.AddEllipse(0, 0, 200, 100)
' Set clipping region to path.
e.Graphics.SetClip(clipPath, CombineMode.Replace)
' Fill rectangle to demonstrate clipping region.
e.Graphics.FillRectangle(New SolidBrush(Color.Black), 0, 0, _
500, 300)
End Sub
Remarks
If the graphics path represented by the path
parameter is not closed, an additional segment is added from the last point to the first point to close the path.
Applies to
SetClip(RectangleF)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
Sets the clipping region of this Graphics to the rectangle specified by a RectangleF structure.
public:
void SetClip(System::Drawing::RectangleF rect);
public void SetClip (System.Drawing.RectangleF rect);
member this.SetClip : System.Drawing.RectangleF -> unit
Public Sub SetClip (rect As RectangleF)
Parameters
- rect
- RectangleF
RectangleF structure that represents the new clip region.
Examples
The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e
, which is a parameter of the Paint event handler. The code performs the following actions:
Creates a small rectangle for the clipping region.
Sets the clipping region to the rectangle.
Fills a large rectangle with a solid black brush.
The result is a small, filled, black rectangle.
public:
void SetClipRectangleF( PaintEventArgs^ e )
{
// Create rectangle for clipping region.
RectangleF clipRect = RectangleF(0.0F,0.0F,100.0F,100.0F);
// Set clipping region of graphics to rectangle.
e->Graphics->SetClip( clipRect );
// Fill rectangle to demonstrate clip region.
e->Graphics->FillRectangle( gcnew SolidBrush( Color::Black ), 0, 0, 500, 300 );
}
private void SetClipRectangleF(PaintEventArgs e)
{
// Create rectangle for clipping region.
RectangleF clipRect = new RectangleF(0.0F, 0.0F, 100.0F, 100.0F);
// Set clipping region of graphics to rectangle.
e.Graphics.SetClip(clipRect);
// Fill rectangle to demonstrate clip region.
e.Graphics.FillRectangle(new SolidBrush(Color.Black), 0, 0, 500, 300);
}
Private Sub SetClipRectangleF(ByVal e As PaintEventArgs)
' Create rectangle for clipping region.
Dim clipRect As New RectangleF(0.0F, 0.0F, 100.0F, 100.0F)
' Set clipping region of graphics to rectangle.
e.Graphics.SetClip(clipRect)
' Fill rectangle to demonstrate clip region.
e.Graphics.FillRectangle(New SolidBrush(Color.Black), 0, 0, _
500, 300)
End Sub
Applies to
SetClip(Rectangle)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
public:
void SetClip(System::Drawing::Rectangle rect);
public void SetClip (System.Drawing.Rectangle rect);
member this.SetClip : System.Drawing.Rectangle -> unit
Public Sub SetClip (rect As Rectangle)
Parameters
Examples
The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e
, which is a parameter of the Paint event handler. The code performs the following actions:
Creates a small rectangle for the clipping region.
Sets the clipping region to the rectangle.
Fills a large rectangle with a solid black brush.
The result is a small, filled, black rectangle.
public:
void SetClipRectangle( PaintEventArgs^ e )
{
// Create rectangle for clipping region.
Rectangle clipRect = Rectangle(0,0,100,100);
// Set clipping region of graphics to rectangle.
e->Graphics->SetClip( clipRect );
// Fill rectangle to demonstrate clip region.
e->Graphics->FillRectangle( gcnew SolidBrush( Color::Black ), 0, 0, 500, 300 );
}
private void SetClipRectangle(PaintEventArgs e)
{
// Create rectangle for clipping region.
Rectangle clipRect = new Rectangle(0, 0, 100, 100);
// Set clipping region of graphics to rectangle.
e.Graphics.SetClip(clipRect);
// Fill rectangle to demonstrate clip region.
e.Graphics.FillRectangle(new SolidBrush(Color.Black), 0, 0, 500, 300);
}
Private Sub SetClipRectangle(ByVal e As PaintEventArgs)
' Create rectangle for clipping region.
Dim clipRect As New Rectangle(0, 0, 100, 100)
' Set clipping region of graphics to rectangle.
e.Graphics.SetClip(clipRect)
' Fill rectangle to demonstrate clip region.
e.Graphics.FillRectangle(New SolidBrush(Color.Black), 0, 0, _
500, 300)
End Sub
Applies to
SetClip(Graphics)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
public:
void SetClip(System::Drawing::Graphics ^ g);
public void SetClip (System.Drawing.Graphics g);
member this.SetClip : System.Drawing.Graphics -> unit
Public Sub SetClip (g As Graphics)
Parameters
Examples
The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e
, which is a parameter of the Paint event handler, as well as thisForm
, the Form for the example. The code performs the following actions:
Creates a temporary Graphics from the
thisForm
Form of the example.Sets the clipping region of the temporary Graphics to a small square.
Updates the clipping region of the form's graphic object to that of the temporary Graphics.
Fills a large rectangle with a solid black brush.
The result is a small, filled, black square.
public:
void SetClipGraphics( PaintEventArgs^ e )
{
// Create temporary graphics object and set its clipping region.
Graphics^ newGraphics = this->CreateGraphics();
newGraphics->SetClip( Rectangle(0,0,100,100) );
// Update clipping region of graphics to clipping region of new
// graphics.
e->Graphics->SetClip( newGraphics );
// Fill rectangle to demonstrate clip region.
e->Graphics->FillRectangle( gcnew SolidBrush( Color::Black ), 0, 0, 500, 300 );
// Release new graphics.
delete newGraphics;
}
private void SetClipGraphics(PaintEventArgs e)
{
// Create temporary graphics object and set its clipping region.
Graphics newGraphics = this.CreateGraphics();
newGraphics.SetClip(new Rectangle(0, 0, 100, 100));
// Update clipping region of graphics to clipping region of new
// graphics.
e.Graphics.SetClip(newGraphics);
// Fill rectangle to demonstrate clip region.
e.Graphics.FillRectangle(new SolidBrush(Color.Black), 0, 0, 500, 300);
// Release new graphics.
newGraphics.Dispose();
}
Private Sub SetClipGraphics(ByVal e As PaintEventArgs)
' Create temporary graphics object and set its clipping region.
Dim newGraphics As Graphics = Me.CreateGraphics()
newGraphics.SetClip(New Rectangle(0, 0, 100, 100))
' Update clipping region of graphics to clipping region of new
' graphics.
e.Graphics.SetClip(newGraphics)
' Fill rectangle to demonstrate clip region.
e.Graphics.FillRectangle(New SolidBrush(Color.Black), 0, 0, _
500, 300)
' Release new graphics.
newGraphics.Dispose()
End Sub
Applies to
SetClip(GraphicsPath)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
Sets the clipping region of this Graphics to the specified GraphicsPath.
public:
void SetClip(System::Drawing::Drawing2D::GraphicsPath ^ path);
public void SetClip (System.Drawing.Drawing2D.GraphicsPath path);
member this.SetClip : System.Drawing.Drawing2D.GraphicsPath -> unit
Public Sub SetClip (path As GraphicsPath)
Parameters
- path
- GraphicsPath
GraphicsPath that represents the new clip region.
Examples
The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e
, which is a parameter of the Paint event handler. The code performs the following actions:
Creates a graphics path and adds an ellipse to the path.
Sets the clipping region to the elliptical path.
Fills a large rectangle with a solid black brush.
The result is a filled, black ellipse.
public:
void SetClipPath( PaintEventArgs^ e )
{
// Create graphics path.
GraphicsPath^ clipPath = gcnew GraphicsPath;
clipPath->AddEllipse( 0, 0, 200, 100 );
// Set clipping region to path.
e->Graphics->SetClip( clipPath );
// Fill rectangle to demonstrate clipping region.
e->Graphics->FillRectangle( gcnew SolidBrush( Color::Black ), 0, 0, 500, 300 );
}
private void SetClipPath(PaintEventArgs e)
{
// Create graphics path.
GraphicsPath clipPath = new GraphicsPath();
clipPath.AddEllipse(0, 0, 200, 100);
// Set clipping region to path.
e.Graphics.SetClip(clipPath);
// Fill rectangle to demonstrate clipping region.
e.Graphics.FillRectangle(new SolidBrush(Color.Black), 0, 0, 500, 300);
}
Private Sub SetClipPath(ByVal e As PaintEventArgs)
' Create graphics path.
Dim clipPath As New GraphicsPath
clipPath.AddEllipse(0, 0, 200, 100)
' Set clipping region to path.
e.Graphics.SetClip(clipPath)
' Fill rectangle to demonstrate clipping region.
e.Graphics.FillRectangle(New SolidBrush(Color.Black), 0, 0, _
500, 300)
End Sub
Remarks
If the graphics path represented by the path
parameter is not closed, an additional segment is added from the last point to the first point to close the path.
Applies to
.NET