实体建模:C#画图的模式与缩放功能

在实体建模软件中,经常有设置并保存各种参考坐标系的功能,方便建立模型。C#画图中也有这种类似功能。不过没有建模软件那么强大。实体建模软件中,可以独立的设置并保存各种坐标系,并随时调用。而这里只能以嵌套的形式调用,当返回到上一级状态时,跳过的状态就不再保存了。

C#画图普通模式主要命令

 
 
 
 
  1. state = graphics.BeginContainer();  
  2. 建一个新绘图状态  
  3.  
  4. e.Graphics.EndContainer(state1);  
  5. 结束这个绘图状态  
  6.  
  7. Rectangle rect = new Rectangle(0,   
  8. 0, 100, 100);//示例图形  
  9.  
  10. GraphicsContainer state1 =   
  11. e.Graphics.BeginContainer();  
  12. //建一个新绘图坐标state1  
  13.  
  14. e.Graphics.TranslateTransform(100, 100);  
  15. //移动坐标系到100,100,画蓝色矩形标记  
  16. e.Graphics.DrawRectangle(Pens.Blue, rect);  
  17. GraphicsContainer state2 =   
  18. e.Graphics.BeginContainer();  
  19. //在此基础上建一个绘图坐标state2  
  20.  
  21. e.Graphics.RotateTransform(45);//旋转45度,  
  22. 画红色矩形标记  
  23. e.Graphics.DrawRectangle(Pens.Red, rect);  
  24.  
  25. e.Graphics.TranslateTransform(100, 100);  
  26. e.Graphics.DrawRectangle(Pens.Black, rect);  
  27.  
  28. e.Graphics.EndContainer(state2);//退出坐标系2,  
  29. 画蓝椭圆  
  30. e.Graphics.DrawEllipse(Pens.Blue, rect);  
  31.  
  32. e.Graphics.EndContainer(state1);//退出state1,  
  33. 画红椭圆  
  34. e.Graphics.DrawRectangle(Pens.Red, rect);  

 

建立状态1

移动到100,100,画蓝色矩形

建被嵌套的状态2

移动到200,0,画红色矩形

退出状态2,画蓝色椭圆

退出状态1,画红色矩形

状态2是被嵌套的,如果直接退出状态1画红色矩形,状态2不再被保存。

graphics.BeginContainer()和EndGontainer是保存和返回当前画板状态,当然,移动只是一种改变画板状态的方式。

C#画图缩放功能主要命令:

 
 
 
 
  1. GraphicsContainercontainerState=  
  2. e.Graphics.BeginContainer(  
  3. destRect,srcRect,  
  4. GraphicsUnit.Pixel);  
  5. 多加两个参数,destRect和scrRect制定缩放大小  
  6. Pixel指定单位  
  7.  
  8. RectanglesrcRect=newRectangle(  
  9. 0,0,200,200);  
  10. RectangledestRect=newRectangle(  
  11. 200,200,100,100);  
  12.  
  13. //建一个比例缩放的画图板.  
  14. GraphicsContainercontainerState=  
  15. e.Graphics.BeginContainer(  
  16. destRect,srcRect,  
  17. GraphicsUnit.Pixel);  
  18.  
  19. //绘图缩放绿矩形.  
  20. e.Graphics.FillRectangle(  
  21. newSolidBrush(Color.Red),0,0,100,100);  
  22.  
  23. //退出此绘图板.  
  24. e.Graphics.EndContainer(containerState);  
  25.  
  26. //绘原始红矩形.  
  27. e.Graphics.FillRectangle(  
  28. newSolidBrush(Color.Green),0,0,100,100);  

以上就介绍了C#画图的模式与缩放功能。

网站栏目:实体建模:C#画图的模式与缩放功能
网页网址:http://www.hantingmc.com/qtweb/news29/385929.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联