文章详细讲解C#画图的模式与缩放功能。实体建模软件中,可以独立的设置并保存各种坐标系,并随时调用。 在实体建模软件中,经常有设置并保存各种参考坐标系的功能,方便建立模型。C#画图中也有这种类似功能。不过没有建模软件那么强大。实体建模软件中,可以独立的设置并保存各种坐标系,并随时调用。而这里只能以嵌套的形式调用,当返回到上一级状态时,跳过的状态就不再保存了。
C#画图普通模式主要命令:
state = graphics.BeginContainer(); 建一个新绘图状态 e.Graphics.EndContainer(state1); 结束这个绘图状态 Rectangle rect = new Rectangle(0, 0, 100, 100);//示例图形 GraphicsContainer state1 = e.Graphics.BeginContainer(); //建一个新绘图坐标state1 e.Graphics.TranslateTransform(100, 100); //移动坐标系到100,100,画蓝色矩形标记 e.Graphics.DrawRectangle(Pens.Blue, rect); GraphicsContainer state2 = e.Graphics.BeginContainer(); //在此基础上建一个绘图坐标state2 e.Graphics.RotateTransform(45);//旋转45度, 画红色矩形标记 e.Graphics.DrawRectangle(Pens.Red, rect); e.Graphics.TranslateTransform(100, 100); e.Graphics.DrawRectangle(Pens.Black, rect); e.Graphics.EndContainer(state2);//退出坐标系2, 画蓝椭圆 e.Graphics.DrawEllipse(Pens.Blue, rect); e.Graphics.EndContainer(state1);//退出state1, 画红椭圆 e.Graphics.DrawRectangle(Pens.Red, rect);建立状态1
移动到100,100,画蓝色矩形
建被嵌套的状态2
移动到200,0,画红色矩形
退出状态2,画蓝色椭圆
退出状态1,画红色矩形
状态2是被嵌套的,如果直接退出状态1画红色矩形,状态2不再被保存。
graphics.BeginContainer()和EndGontainer是保存和返回当前画板状态,当然,移动只是一种改变画板状态的方式。
C#画图缩放功能主要命令:
GraphicsContainer containerState= e.Graphics.BeginContainer( destRect,srcRect, GraphicsUnit.Pixel); // 多加两个参数,destRect和scrRect制定缩放大小 Pixel指定单位 Rectangle srcRect=newRectangle( 0,0,200,200); Rectangle destRect=newRectangle( 200,200,100,100); //建一个比例缩放的画图板. GraphicsContainer containerState= e.Graphics.BeginContainer( destRect,srcRect, GraphicsUnit.Pixel); //绘图缩放绿矩形. e.Graphics.FillRectangle( newSolidBrush(Color.Red),0,0,100,100); //退出此绘图板. e.Graphics.EndContainer(containerState); //绘原始红矩形. e.Graphics.FillRectangle( newSolidBrush(Color.Green),0,0,100,100);以上就介绍了C#画图的模式与缩放功能。
转载于:https://www.cnblogs.com/Fly-sky/archive/2010/10/26/1861222.html
相关资源:C#绘图和图片放大缩小等功能代码