直线的虚线摸板(DashArray)指出了虚线的模式和间隔。下面的例子使用了不同的Dash Pattern来显示同一条线段。
private void Dashes() { Color blackColor = new Color(0x000000); int[] dashArray1 = { 2, 2 }; int[] dashArray2 = { 6, 6 }; int[] dashArray3 = { 4, 1, 2, 1, 1, 6 }; graphics2D.Reset(); graphics2D.Clear(Color.White); Pen pen = new Pen(blackColor, 20, Pen.CapButt, Pen.JoinMiter, dashArray1, 0); graphics2D.DrawLine(pen, 40, 60, 140, 60); pen = new Pen(blackColor, 20, Pen.CapButt, Pen.JoinMiter, dashArray2, 0); graphics2D.DrawLine(pen, 40, 100, 140, 100); pen = new Pen(blackColor, 20, Pen.CapButt, Pen.JoinMiter, dashArray3, 0); graphics2D.DrawLine(pen, 40, 140, 140, 140); }