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; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void Form1_Paint(object sender, PaintEventArgs e) { } } public class LineShape : Label { public Color PenColor; public float _Width; PointF _StartPoint; PointF _EndPoint; public LineShape() { PenColor = Color.Black; _Width = 1.0f; _StartPoint = new PointF(0.0f, 0.0f); _EndPoint = new PointF(100.0f, 0.0f); this.Paint += new PaintEventHandler(LineShape_Paint); } void LineShape_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Pen p = new Pen(PenColor,_Width); p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; g.DrawLine(p,_StartPoint,_EndPoint); p.Dispose(); } public float PenWidth { get { return _Width; } set { _Width = value; this.ppp(); } } public PointF StartPoint { get { return _StartPoint; } set { _StartPoint = value; this.ppp(); } } public PointF EndPoint { get { return _EndPoint; } set { _EndPoint = value; this.ppp(); } } private void ppp() { this.ClientSize = new Size((int)_EndPoint.X+1, (int)_EndPoint.Y+1); } } }