實體建模:C#畫圖的模式與縮放功能

來源:互聯網
上載者:User

文章詳細講解C#畫圖的模式與縮放功能。實體建模軟體中,可以獨立的設定並儲存各種座標系,並隨時調用。
在實體建模軟體中,經常有設定並儲存各種參考座標系的功能,方便建立模型。C#畫圖中也有這種類似功能。不過沒有建模軟體那麼強大。實體建模軟體中,可以獨立的設定並儲存各種座標系,並隨時調用。而這裡只能以嵌套的形式調用,當返回到上一級狀態時,跳過的狀態就不再儲存了。

C#畫圖普通模式主要命令:

 
  1. state = graphics.BeginContainer();  建一個新繪圖狀態 
  2. e.Graphics.EndContainer(state1);  結束這個繪圖狀態 
  3. Rectangle rect = new Rectangle(0,   0, 100, 100);//樣本圖形 
  4.  
  5. GraphicsContainer state1 = 
  6.   e.Graphics.BeginContainer();  //建一個新繪圖座標state1 
  7. e.Graphics.TranslateTransform(100, 100); 
  8.   //移動座標繫到100,100,畫藍色矩形標記 
  9. e.Graphics.DrawRectangle(Pens.Blue, rect); 
  10.  
  11. GraphicsContainer state2 = 
  12.   e.Graphics.BeginContainer();  //在此基礎上建一個繪圖座標state2 
  13. e.Graphics.RotateTransform(45);//旋轉45度,  畫紅色矩形標記 
  14. e.Graphics.DrawRectangle(Pens.Red, rect); 
  15. e.Graphics.TranslateTransform(100, 100); 
  16. e.Graphics.DrawRectangle(Pens.Black, rect); 
  17. e.Graphics.EndContainer(state2);//退出座標系2,  畫藍橢圓 
  18.  
  19. e.Graphics.DrawEllipse(Pens.Blue, rect); 
  20. e.Graphics.EndContainer(state1);//退出state1,  畫紅橢圓 
  21. e.Graphics.DrawRectangle(Pens.Red, rect);    

建立狀態1

移動到100,100,畫藍色矩形

建被嵌套的狀態2

移動到200,0,畫紅色矩形

退出狀態2,畫藍色橢圓

退出狀態1,畫紅色矩形

狀態2是被嵌套的,如果直接退出狀態1畫紅色矩形,狀態2不再被儲存。

graphics.BeginContainer()和EndGontainer是儲存和返回當前畫板狀態,當然,移動只是一種改變畫板狀態的方式。

C#畫圖縮放功能主要命令:

 
  1. GraphicsContainer containerState= 
  2.   e.Graphics.BeginContainer(  destRect,srcRect,  GraphicsUnit.Pixel); 
  3.  
  4. //  多加兩個參數,destRect和scrRect制定縮放大小  Pixel指定單位 
  5. Rectangle srcRect=newRectangle(  0,0,200,200); 
  6. Rectangle destRect=newRectangle(  200,200,100,100);   //建一個比例縮放的畫圖板. 
  7. GraphicsContainer containerState=  e.Graphics.BeginContainer( 
  8.   destRect,srcRect,  GraphicsUnit.Pixel);   //繪圖縮放綠矩形. 
  9. e.Graphics.FillRectangle(  newSolidBrush(Color.Red),0,0,100,100);   //退出此繪圖板. 
  10. e.Graphics.EndContainer(containerState);   //繪原始紅矩形. 
  11. e.Graphics.FillRectangle(  newSolidBrush(Color.Green),0,0,100,100);

  以上就介紹了C#畫圖的模式與縮放功能。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.