Export (0) Print
Expand All

Graphics.SetClip Method

Sets the clipping region of this Graphics object to the Clip property of the specified Graphics object.

Overload List

Sets the clipping region of this Graphics object to the Clip property of the specified Graphics object.

[Visual Basic] Overloads Public Sub SetClip(Graphics)
[C#] public void SetClip(Graphics);
[C++] public: void SetClip(Graphics*);
[JScript] public function SetClip(Graphics);

Sets the clipping region of this Graphics object to the specified GraphicsPath object.

[Visual Basic] Overloads Public Sub SetClip(GraphicsPath)
[C#] public void SetClip(GraphicsPath);
[C++] public: void SetClip(GraphicsPath*);
[JScript] public function SetClip(GraphicsPath);

Sets the clipping region of this Graphics object to the rectangle specified by a Rectangle structure.

[Visual Basic] Overloads Public Sub SetClip(Rectangle)
[C#] public void SetClip(Rectangle);
[C++] public: void SetClip(Rectangle);
[JScript] public function SetClip(Rectangle);

Sets the clipping region of this Graphics object to the rectangle specified by a RectangleF structure.

[Visual Basic] Overloads Public Sub SetClip(RectangleF)
[C#] public void SetClip(RectangleF);
[C++] public: void SetClip(RectangleF);
[JScript] public function SetClip(RectangleF);

Sets the clipping region of this Graphics object to the result of the specified combining operation of the current clip region and the Clip property of the specified Graphics object.

[Visual Basic] Overloads Public Sub SetClip(Graphics, CombineMode)
[C#] public void SetClip(Graphics, CombineMode);
[C++] public: void SetClip(Graphics*, CombineMode);
[JScript] public function SetClip(Graphics, CombineMode);

Sets the clipping region of this Graphics object to the result of the specified operation combining the current clip region and the specified GraphicsPath object.

[Visual Basic] Overloads Public Sub SetClip(GraphicsPath, CombineMode)
[C#] public void SetClip(GraphicsPath, CombineMode);
[C++] public: void SetClip(GraphicsPath*, CombineMode);
[JScript] public function SetClip(GraphicsPath, CombineMode);

Sets the clipping region of this Graphics object to the result of the specified operation combining the current clip region and the rectangle specified by a Rectangle structure.

[Visual Basic] Overloads Public Sub SetClip(Rectangle, CombineMode)
[C#] public void SetClip(Rectangle, CombineMode);
[C++] public: void SetClip(Rectangle, CombineMode);
[JScript] public function SetClip(Rectangle, CombineMode);

Sets the clipping region of this Graphics object to the result of the specified operation combining the current clip region and the rectangle specified by a RectangleF structure.

[Visual Basic] Overloads Public Sub SetClip(RectangleF, CombineMode)
[C#] public void SetClip(RectangleF, CombineMode);
[C++] public: void SetClip(RectangleF, CombineMode);
[JScript] public function SetClip(RectangleF, CombineMode);

Sets the clipping region of this Graphics object to the result of the specified operation combining the current clip region and the specified Region object.

[Visual Basic] Overloads Public Sub SetClip(Region, CombineMode)
[C#] public void SetClip(Region, CombineMode);
[C++] public: void SetClip(Region*, CombineMode);
[JScript] public function SetClip(Region, CombineMode);

Example

[Visual Basic, C#] The following 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 CombineMode.Replace member.
  • Fills a large rectangle with a solid black brush.

[Visual Basic, C#] The result is a small, filled, black rectangle.

[Visual Basic, C#] Note   This example shows how to use one of the overloaded versions of SetClip. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Public Sub SetClipRegionCombine(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
        
[C#] 
public 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);
}
        

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Graphics Class | Graphics Members | System.Drawing Namespace

Show:
© 2014 Microsoft