GDI+基础知识——画笔的线帽属性示意

//线帽演示
private void Pen_LineCap_Click(object sender, System.EventArgs e) { Graphics graphics = this.CreateGraphics(); graphics.Clear(Color.White); //设置文本输出对齐方式及字体 StringFormat fmt = new StringFormat(); fmt.Alignment = StringAlignment.Near; fmt.LineAlignment = StringAlignment.Center; //字体 Font font = new Font("Arial",12); SolidBrush sBrush = new SolidBrush(Color.Red); //创建宽度为15的画笔 Pen pen = new Pen(Color.Black,15); //分别使用不同的线帽 foreach (LineCap lincap in Enum.GetValues(typeof(LineCap))) { pen.StartCap = lincap;//起点 pen.EndCap = lincap;//终点 graphics.DrawLine(pen,50,10,300,10); //输出当前线帽类型(LineCap枚举成员名) graphics.DrawString(pen.StartCap.ToString(), font,sBrush,new Point(320,10),fmt); //平移绘图平面 graphics.TranslateTransform(0,30); } }
浙公网安备 33010602011771号