Clip many shapes : Region Clip « 2D Graphics « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » 2D Graphics » Region ClipScreenshots 
Clip many shapes
Clip many shapes


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

public class Form1 : Form
{
    private System.Windows.Forms.CheckBox chkClipping;
  public Form1() {
        InitializeComponent();
  }

  private void checkBox1_CheckedChanged(object sender, EventArgs e)
  {
    Invalidate();
  }  
  private void Form1_Paint(object sender, PaintEventArgs e)
  {
    e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
    GraphicsPath path = new GraphicsPath();
    
    Region clippingRegion = new Region(path);
    if (chkClipping.Checkede.Graphics.Clip = clippingRegion;

    e.Graphics.ResetClip();
    
    path = new GraphicsPath();
    path.AddString("www.java2java.com"new FontFamily("Verdana")070new Point(10130)new StringFormat());
    e.Graphics.DrawPath(Pens.Blue, path);

    clippingRegion = new Region(path);
    if (chkClipping.Checkede.Graphics.Clip = clippingRegion;

    for (int i = 0; i < 40; i++)
    {
      e.Graphics.DrawEllipse(Pens.Red, 180 - i*3180 - i*3, i*6, i*6);      
    }
    clippingRegion.Dispose();
    path.Dispose();

  }

  private void InitializeComponent()
  {
    this.chkClipping = new System.Windows.Forms.CheckBox();
    this.SuspendLayout();
    // 
    // chkClipping
    // 
    this.chkClipping.AutoSize = true;
    this.chkClipping.Checked = true;
    this.chkClipping.CheckState = System.Windows.Forms.CheckState.Checked;
    this.chkClipping.Location = new System.Drawing.Point(12300);
    this.chkClipping.Name = "chkClipping";
    this.chkClipping.Size = new System.Drawing.Size(8017);
    this.chkClipping.TabIndex = 0;
    this.chkClipping.Text = "Use Clipping";
    this.chkClipping.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
    // 
    // Form1
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(292329);
    this.Controls.Add(this.chkClipping);
    this.Font = new System.Drawing.Font("Tahoma"8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    this.Name = "Form1";
    this.Text = "Clipping";
    this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
    this.ResumeLayout(false);
    this.PerformLayout();

  }
  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }

}


           
       
Related examples in the same category
1.Text region clips shapeText region clips shape
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.