C Method for Graphic Area Combination
- 2021-06-28 13:40:29
- OfStack
This paper describes an example of how C#achieves the grouping of graphical regions.Share it for your reference.The implementation is as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace advanced_drawing
{
public partial class Form17 : Form
{
public Form17()
{
InitializeComponent();
}
private void Form17_Paint(object sender, PaintEventArgs e)
{
Rectangle regionRect = new Rectangle(20, 20, 100, 100);
e.Graphics.DrawRectangle(Pens.Black, regionRect);
RectangleF unionRect = new RectangleF(90, 30, 100, 100);
e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(unionRect));
Region myRegion = new Region(regionRect);
//myRegion.Union(unionRect);
//myRegion.Intersect(unionRect);
//myRegion.Exclude(unionRect);
//myRegion.Complement(unionRect);
myRegion.Xor(unionRect);
SolidBrush myBrush = new SolidBrush(Color.Blue);
e.Graphics.FillRegion(myBrush, myRegion);
}
}
}
I hope that the description in this paper will be helpful to everyone's C#program design.