c#图形区域组合操作

来源:互联网 发布:js prompt函数 编辑:程序博客网 时间:2024/04/29 21:43
 
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace advanced_drawing
  9. {
  10.     public partial class Form17 : Form
  11.     {
  12.         public Form17()
  13.         {
  14.             InitializeComponent();
  15.         }
  16.         private void Form17_Paint(object sender, PaintEventArgs e)
  17.         {
  18.             Rectangle regionRect = new Rectangle(20, 20, 100, 100);
  19.             e.Graphics.DrawRectangle(Pens.Black, regionRect);
  20.             RectangleF unionRect = new RectangleF(90, 30, 100, 100);
  21.             e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(unionRect));
  22.             Region myRegion = new Region(regionRect);
  23.             //myRegion.Union(unionRect);
  24.             //myRegion.Intersect(unionRect);
  25.             //myRegion.Exclude(unionRect);
  26.             //myRegion.Complement(unionRect);
  27.             myRegion.Xor(unionRect);
  28.             SolidBrush myBrush = new SolidBrush(Color.Blue);
  29.             e.Graphics.FillRegion(myBrush, myRegion);
  30.         }
  31.     }
  32. }
原创粉丝点击