Graphics.Clip Property

Gets or sets a Region that limits the drawing region of this Graphics.

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

public Region Clip { get; set; }
/** @property */
public Region get_Clip ()

/** @property */
public void set_Clip (Region value)

public function get Clip () : Region

public function set Clip (value : Region)

Not applicable.

Property Value

A Region that limits the portion of this Graphics that is currently available for drawing.

To determine whether the clipping region is infinite, retrieve the Clip property and call its IsInfinite method.

The following code example demonstrates the use of the Clip property. This example is designed to be used with Windows Forms. Paste the code into a form and call the SetAndFillClip method when handling the form's Paint event, passing e as PaintEventArgs.

private void SetAndFillClip(PaintEventArgs e)
{

    // Set the Clip property to a new region.
    e.Graphics.Clip = new Region(new Rectangle(10, 10, 100, 200));

    // Fill the region.
    e.Graphics.FillRegion(Brushes.LightSalmon, e.Graphics.Clip);

    // Demonstrate the clip region by drawing a string
    // at the outer edge of the region.
    e.Graphics.DrawString("Outside of Clip", new Font("Arial", 
        12.0F, FontStyle.Regular), Brushes.Black, 0.0F, 0.0F);

}

private void SetAndFillClip(PaintEventArgs e)
{
    // Set the Clip property to a new region.
    e.get_Graphics().set_Clip(new Region(new Rectangle(10, 10, 100, 200)));

    // Fill the region.
    e.get_Graphics().FillRegion(Brushes.get_LightSalmon(),
        e.get_Graphics().get_Clip());

    // Demonstrate the clip region by drawing a string
    // at the outer edge of the region.
    e.get_Graphics().DrawString("Outside of Clip", 
        new Font("Arial", 12, FontStyle.Regular), 
        Brushes.get_Black(), 0, 0);
} //SetAndFillClip

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, 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

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show: