⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sample12.cs

📁 C#函数手册
💻 CS
字号:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
public class testAnimateImage : Form 
{
	Bitmap testB = new Bitmap("C:\\w2k.jpg");
	bool flag = false;	
	private void OnFrameChanged(object o, EventArgs e) 
	{
		this.Invalidate();
	}
	protected override void OnPaint(PaintEventArgs e) 
	{		
		Rectangle testR1 = new Rectangle(20, 20, 30, 30);
		e.Graphics.DrawRectangle(Pens.Black, testR1);
		Rectangle testR2 = new Rectangle(35, 20, 40, 30);
		e.Graphics.DrawRectangle(Pens.Red, testR2);
		Region testRn1 = new Region(testR1);
		Region testRn2 = new Region(testR2);
		testRn1.Complement(testR2);
		//使用Complement方法将Region对象更新为指定的RectangleF结构中与此Region对象不相交的部分
			SolidBrush testB = new SolidBrush(Color.Black);
		e.Graphics.FillRegion(testB, testRn1);
		testR2 = new Rectangle(50, 20, 65, 30);
		e.Graphics.DrawEllipse(Pens.Red,Rectangle.Round(testR2));
		testRn1.Exclude(testR2);
		//使用Exclude方法将Region对象更新为仅包含其内部与指定Rectangle结构不相交的部分
		testB = new SolidBrush(Color.Blue);
		e.Graphics.FillRegion(testB, testRn1);
		GraphicsPath testP = new GraphicsPath();
		testP.AddEllipse(testR1);
		testB.Color = Color.Yellow;
		e.Graphics.FillPath(testB, testP);
		RectangleF testRF = testRn1.GetBounds(e.Graphics);
		e.Graphics.DrawRectangle(Pens.Red, 
			Rectangle.Round(testRF));
		RegionData testRD = testRn1.GetRegionData();
		//使用GetRegionData方法获取描述此Region对象信息的RegionData对象
		int length = testRD.Data.Length;
		int i;
		float x = 20, y = 90;
		Font tempF = new Font("Arial", 8);
		SolidBrush sb = new SolidBrush(Color.Black);
		e.Graphics.DrawString("区域数据:",tempF,sb,
			new PointF(x, y));
		y = 100;
		for(i = 0; i < length; i++)
		{
			if(x > 300)
			{
				y += 10;
				x = 20;
			}
			e.Graphics.DrawString(testRD.Data[i].ToString(),tempF,sb,
				new PointF(x, y));
			x += 25;
		}
		testRn1.Intersect(testR1);
		//使用Intersect方法将Region对象更新为其自身与指定Region对象的交集
		testB.Color=Color.Red;
		e.Graphics.FillRegion(testB, testRn1);
		bool flag = testRn1.IsVisible(testR1);
		Font testF = new Font("Arial", 8);
		e.Graphics.DrawString("testRn1.IsVisible(testR1)值为: " + 
			flag.ToString(),testF,testB,new PointF(20, 75));
		Matrix testM = new Matrix();
		testM.RotateAt(15, new Point(120, 50));
		testRn1.Transform(testM);
		//使用Transform方法用指定的Matrix对象变换此Region对象
		e.Graphics.FillRegion(testB, testRn1);
		testRn1.Translate(150, 40);
		//使用Translate方法使此Region对象的坐标偏移指定的量
		testB.Color=Color.Green;
		testR2 = new Rectangle(65, 190, 70, 200);
		e.Graphics.DrawRectangle(Pens.Red,
			Rectangle.Round(testR2));
		testRn1.Union(testR2);
		//使用Union方法将此Region对象更新为其自身与指定
		//GraphicsPath对象的并集
		e.Graphics.FillRegion(testB, testRn1);
		testR2 = new Rectangle(180, 190, 85, 200);
		e.Graphics.DrawRectangle(Pens.Red,
			Rectangle.Round(testR2));
		testRn1.Xor(testR1);
		//使用Xor方法将此Region对象更新为其自身与指定
		//GraphicsPath对象的并集减去这两者的交集
		e.Graphics.FillRegion(testB, testRn1);
		testRn1.Dispose();
		//使用Dispose方法释放资源
	}


	public static void Main() 
	{
		Application.Run(new testAnimateImage());
	}

	private void InitializeComponent()
	{
		// 
		// testAnimateImage
		// 
		this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
		this.ClientSize = new System.Drawing.Size(292, 273);
		this.Name = "testAnimateImage";
		//this.Load += new System.EventHandler(this.testAnimateImage_Load);

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -