以Microsoft C# Windows程序設計為例,理解PageUnit和PageScale的用法
互聯網 2022/5/2 7:14:02

Microsoft windows 程序設計,第250頁中,使用不同的枚舉值,來求得“一英寸長的直線”,達到相同的目標。
對于以上代碼,我編寫了實例進行實踐,代碼如下:
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Drawing; 6 using System.Windows.Forms; 7 8 namespace PageUnitDemo 9 { 10 class PageUnitDemo:Form 11 { 12 static void Main(string[] args) 13 { 14 Application.Run(new PageUnitDemo()); 15 } 16 public PageUnitDemo() 17 { 18 Text = "Page Unit 試驗!"; 19 } 20 protected override void OnPaint(PaintEventArgs e) 21 { 22 Graphics grfx = e.Graphics; 23 24 grfx.PageUnit = GraphicsUnit.Inch; 25 grfx.PageScale = 0.01f; 26 27 grfx.DrawLine((new Pen(ForeColor)),0,10,100,10); 28 29 grfx.PageUnit = GraphicsUnit.Document; 30 grfx.PageScale = 3; 31 32 grfx.DrawLine(new Pen(ForeColor),0,20,100,20); 33 34 grfx.PageUnit = GraphicsUnit.Pixel; 35 grfx.PageScale = 1 ; 36 37 grfx.DrawLine(new Pen(ForeColor), 0, 30, 96, 30); 38 39 grfx.PageUnit = GraphicsUnit.Millimeter; 40 grfx.PageScale = 0.254f; 41 42 grfx.DrawLine(new Pen(ForeColor), 0, 40, 100, 40); 43 44 grfx.PageUnit = GraphicsUnit.Point; 45 grfx.PageScale = 0.72f; 46 47 grfx.DrawLine(new Pen(ForeColor), 0, 50, 100, 50); 48 } 49 } 50 }
從以上結果可以看到,繪制的直線長度都是一樣的;
其中,pixel是像素單位,pixel與inch之間的換算關系為:inch = pixel / 96
綜合上述五種換算關系,總結為:DrawLine函數中的線長度*PageScale = 一個單位的PageUnit.枚舉值;

關于找一找教程網
本站文章僅代表作者觀點,不代表本站立場,所有文章非營利性免費分享。
本站提供了軟件編程、網站開發技術、服務器運維、人工智能等等IT技術文章,希望廣大程序員努力學習,讓我們用科技改變世界。
[以Microsoft C# Windows程序設計為例,理解PageUnit和PageScale的用法]http://www.yachtsalesaustralia.com/tech/detail-318689.html
- 2022-03-01沐雪多租寶商城源碼從.NetCore3.1升級到.Net6的步驟
- 2022-05-19聊聊C#中的Visitor模式
- 2022-05-19C# Async / Await State Machine
- 2022-05-19c#控件的Anchor屬性、Dock屬性--影響布局c#控件的Anchor屬性、Dock屬性--影響布局
- 2022-05-19c#字符串按照1.1,1.1.1,2.1,2.1.1排序
- 2022-05-19C# 獲取當前月份天數的三種方法總結
- 2022-05-19【C# 數據結構與算法】二叉樹
- 2022-05-19【低碼】asp.net core 實體類可生產 CRUD 后臺管理界面
- 2022-05-19C# 工具類
- 2022-05-19【C# 數據結構與算法】樹