Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Graphics.SetClip Method (Rectangle)

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

Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)

public void SetClip (
	Rectangle rect
)
public void SetClip (
	Rectangle rect
)
public function SetClip (
	rect : Rectangle
)
Not applicable.

Parameters

rect

Rectangle structure that represents the new clip region.

The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, 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.

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);
}

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.