Permalink
Fetching contributors…
Cannot retrieve contributors at this time
42 lines (35 sloc) 1.97 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
How to: Use Clipping with a Region
03/30/2017
.net-framework
dotnet-winforms
article
jsharp
regions, clipping
regions, restricting drawing surface
43d121b4-e14c-4901-b25c-2d6c25ba4e29
14
dotnet-bot
dotnetcontent
wpickett

How to: Use Clipping with a Region

One of the properties of the xref:System.Drawing.Graphics class is the clip region. All drawing done by a given xref:System.Drawing.Graphics object is restricted to the clip region of that xref:System.Drawing.Graphics object. You can set the clip region by calling the xref:System.Drawing.Graphics.SetClip%2A method.

Example

The following example constructs a path that consists of a single polygon. Then the code constructs a region, based on that path. The region is passed to the xref:System.Drawing.Graphics.SetClip%2A method of a xref:System.Drawing.Graphics object, and then two strings are drawn.

The following illustration shows the clipped strings.

Clip

[!code-csharpSystem.Drawing.MiscLegacyTopics#41] [!code-vbSystem.Drawing.MiscLegacyTopics#41]

Compiling the Code

The preceding example is designed for use with Windows Forms, and it requires xref:System.Windows.Forms.PaintEventArgs e, which is a parameter of xref:System.Windows.Forms.PaintEventHandler.

See Also

Regions in GDI+
Using Regions