## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

### 6.4. Clipping Regions Example

Listing 6.14 uses Xor to clip regions.

##### Listing 6.14. Using the Xor method
 ```Pen pen = new Pen(Color.Red, 5); SolidBrush brush = new SolidBrush(Color.Red); Rectangle rect1 = new Rectangle(50, 0, 50, 150); Rectangle rect2 = new Rectangle(0, 50, 150, 50); Region region = new Region(rect1); region.Xor(rect2); g.FillRegion(brush, region); ```

Figure 6.14 shows the output from Listing 6.14.

##### Figure 6.14. Result of the Xor method

Now if we replace Xor with Union:

```region.Union(rect2);
```

the new output looks like Figure 6.15.

##### Figure 6.15. Result of the Union method

Now let’s replace Union with Exclude:

` region.Exclude(rect2); ...`

## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

No credit card required