跟着 伍逸 老師學GDI+ 之Pen.CompoundArray屬性

Pen.CompoundArray是一個數組,該數組包含四個元素,第一個元素是指Pen是最上側開始的位置(相對Pen的寬度來講),第二個元素是從上側延伸到的位置,第三個元素是從上往下退縮的寬度,最後一個元素是從下往上退縮的寬度。

測試代碼如下:

 

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9. using System.Drawing.Drawing2D;  
  10. namespace _003點_直線和曲線  
  11. {  
  12.     public partial class Form1 : Form  
  13.     {  
  14.         public Form1()  
  15.         {  
  16.             InitializeComponent();  
  17.         }  
  18.         protected override void OnPaint(PaintEventArgs e)  
  19.         {  
  20.             //base.OnPaint(e);  
  21.             Graphics G = e.Graphics;    // 構造Graphics對象  
  22.             Pen p1 = new Pen(Color.Blue,10);    // 實例化Pen對象  
  23.             G.DrawLine(p1,20,20,330,20);        // 畫直線  
  24.  
  25.             Pen p2 = new Pen(Color.Blue,5);    // 實例化Pen對象  
  26.             float[] Pts = { 3,1,2,5};           // 定義一個浮點型數組  
  27.             p2.DashStyle = DashStyle.Dash;      // 定義Pen p2的DashStyle類型爲DashStye  
  28.             p2.DashPattern = Pts;  
  29.             p2.DashCap = DashCap.Triangle;  
  30.             p2.StartCap = LineCap.Triangle;  
  31.             p2.EndCap = LineCap.ArrowAnchor;  
  32.             G.DrawLine(p2, 20, 50, 330, 50);  
  33.  
  34.             Pen p3 = new Pen(Color.Blue,100);  
  35.             Single[] lines = { 0.0f, 0.1f, 0.9f, 1.0f };  
  36.             p3 = new Pen(Color.Blue, 100);  
  37.             p3.CompoundArray = lines;  
  38.             e.Graphics.DrawLine(p3,20,180,330,180);  
  39.               
  40.         }  
  41.     }  
  42. }  

 

將數組lines改爲:Single[] lines = { 0.0f, 0.3f, 0.9f, 1.0f };

 

 

可以明顯看到上側的寬度向中間延伸了。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章