using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing.Drawing2D; namespace WMS.Ctrl { public partial class LineY : UserControl { public LineY() { InitializeComponent(); this.lineColor = Color.Green; this.lineWidth = 5; this.Name = "LineY"; this.SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.Opaque, true); this.BackColor = Color.Transparent; this.Resize += new System.EventHandler(this.LineY_Resize); this.Paint += new System.Windows.Forms.PaintEventHandler(this.LineY_Paint); } protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle = 0x20; return cp; } } #region 属性定义 private System.Drawing.Color lineColor; private int lineWidth; /// /// 线的颜色属性 /// public System.Drawing.Color LineColor { set { this.lineColor = value; System.Windows.Forms.PaintEventArgs ep = new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle); this.LineY_Paint(this, ep); } get { return this.lineColor; } } /// /// 线的粗细 /// public int LineWidth { set { this.lineWidth = value; System.Windows.Forms.PaintEventArgs ep = new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle); this.LineY_Paint(this, ep); } get { return this.lineWidth; } } #endregion private int lStartCap; public int LStartCap { set { this.lStartCap = value; System.Windows.Forms.PaintEventArgs ep = new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle); this.LineY_Paint(this, ep); } get { return this.lStartCap; } } private int lEndCap; public int LEndCap { set { this.lEndCap = value; System.Windows.Forms.PaintEventArgs ep = new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle); this.LineY_Paint(this, ep); } get { return this.lEndCap; } } private void LineY_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Pen p = new Pen(this.LineColor, this.LineWidth);//设置笔的粗细为,颜色为蓝色 Graphics g = this.CreateGraphics(); //p.EndCap = LineCap.ArrowAnchor;//定义线尾的样式为箭头 if (LEndCap == 1) { p.EndCap = LineCap.ArrowAnchor;//定义线尾的样式为箭头 } else { p.EndCap = LineCap.NoAnchor; //p.DashStyle = DashStyle.Solid;//恢复实线 } if (LStartCap == 1) { p.StartCap = LineCap.ArrowAnchor;//定义线尾的样式为箭头 } else { p.StartCap = LineCap.NoAnchor; //p.DashStyle = DashStyle.Solid;//恢复实线 } g.DrawLine(p, (this.LineWidth), 0, (this.LineWidth), e.ClipRectangle.Bottom); this.Width = (this.LineWidth * 2); g.Dispose(); p.Dispose(); //Graphics g = e.Graphics; //Pen myPen = new Pen(this.lineColor); //myPen.Width = this.lineWidth * 2; //this.Width = this.LineWidth; //g.DrawLine(myPen, 0, 0, 0, e.ClipRectangle.Bottom); } private void LineY_Resize(object sender, System.EventArgs e) { this.Width = (this.LineWidth * 2); } } }