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

graphics/06fig14.gif

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

graphics/06fig15.gif

Now let's replace Union with Exclude:


 
region.Exclude(rect2);

 

The output looks like Figure 6.16.

Figure 6.16. Result of the Exclude method

graphics/06fig16.gif

If we use the Intersect method:


 
region.Intersect(rect2);

 

the output looks like Figure 6.17.

Figure 6.17. Result of the Intersect method

graphics/06fig17.gif

GDI+: The Next-Generation Graphics Interface

Your First GDI+ Application

The Graphics Class

Working with Brushes and Pens

Colors, Fonts, and Text

Rectangles and Regions

Working with Images

Advanced Imaging

Advanced 2D Graphics

Transformation

Printing

Developing GDI+ Web Applications

GDI+ Best Practices and Performance Techniques

GDI Interoperability

Miscellaneous GDI+ Examples

Appendix A. Exception Handling in .NET



GDI+ Programming with C#
GDI+ Programming with C#
ISBN: 073561265X
EAN: N/A
Year: 2003
Pages: 145

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net