Pen.CompoundArray是一個數組,該數組包含四個元素,第一個元素是指Pen是最上側開始的位置(相對Pen的寬度來講),第二個元素是從上側延伸到的位置,第三個元素是從上往下退縮的寬度,最後一個元素是從下往上退縮的寬度。
測試代碼如下:
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Drawing.Drawing2D;
- namespace _003點_直線和曲線
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- //base.OnPaint(e);
- Graphics G = e.Graphics; // 構造Graphics對象
- Pen p1 = new Pen(Color.Blue,10); // 實例化Pen對象
- G.DrawLine(p1,20,20,330,20); // 畫直線
- Pen p2 = new Pen(Color.Blue,5); // 實例化Pen對象
- float[] Pts = { 3,1,2,5}; // 定義一個浮點型數組
- p2.DashStyle = DashStyle.Dash; // 定義Pen p2的DashStyle類型爲DashStye
- p2.DashPattern = Pts;
- p2.DashCap = DashCap.Triangle;
- p2.StartCap = LineCap.Triangle;
- p2.EndCap = LineCap.ArrowAnchor;
- G.DrawLine(p2, 20, 50, 330, 50);
- Pen p3 = new Pen(Color.Blue,100);
- Single[] lines = { 0.0f, 0.1f, 0.9f, 1.0f };
- p3 = new Pen(Color.Blue, 100);
- p3.CompoundArray = lines;
- e.Graphics.DrawLine(p3,20,180,330,180);
- }
- }
- }
將數組lines改爲:Single[] lines = { 0.0f, 0.3f, 0.9f, 1.0f };
可以明顯看到上側的寬度向中間延伸了。