155 lines
4.3 KiB
C#
155 lines
4.3 KiB
C#
|
|
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 LineX : UserControl
|
|||
|
|
{
|
|||
|
|
public LineX()
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
this.Name = "LineX";
|
|||
|
|
this.lineWidth = 5;
|
|||
|
|
this.lineColor = Color.Green;
|
|||
|
|
this.SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.Opaque, true);
|
|||
|
|
this.BackColor = Color.Transparent;
|
|||
|
|
this.Paint += new PaintEventHandler(LineX_Paint);
|
|||
|
|
this.Resize += new EventHandler(LineX_Resize);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
protected override CreateParams CreateParams
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
CreateParams cp = base.CreateParams;
|
|||
|
|
cp.ExStyle = 0x20;
|
|||
|
|
return cp;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#region 定义属性
|
|||
|
|
private Color lineColor;
|
|||
|
|
/// <summary>
|
|||
|
|
/// 定义线的颜色
|
|||
|
|
/// </summary>
|
|||
|
|
public Color LineColor
|
|||
|
|
{
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
this.lineColor = value;
|
|||
|
|
System.Windows.Forms.PaintEventArgs ep = new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle);
|
|||
|
|
this.LineX_Paint(this, ep);
|
|||
|
|
}
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return this.lineColor;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private int lineWidth;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 定义线的粗细
|
|||
|
|
/// </summary>
|
|||
|
|
public int LineWidth
|
|||
|
|
{
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
this.lineWidth = value;
|
|||
|
|
System.Windows.Forms.PaintEventArgs ep = new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle);
|
|||
|
|
this.LineX_Paint(this, ep);
|
|||
|
|
}
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return this.lineWidth;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private int lStartCap;
|
|||
|
|
public int LStartCap
|
|||
|
|
{
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
this.lStartCap = value;
|
|||
|
|
System.Windows.Forms.PaintEventArgs ep = new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle);
|
|||
|
|
this.LineX_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.LineX_Paint(this, ep);
|
|||
|
|
}
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return this.lEndCap;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 控件调整大小时发生的事件
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void LineX_Resize(object sender, System.EventArgs e)
|
|||
|
|
{
|
|||
|
|
this.Height = (this.LineWidth * 2);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 控件重绘时发生的事件
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void LineX_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
|
|||
|
|
{
|
|||
|
|
Pen p = new Pen(this.LineColor, this.LineWidth);//设置笔的粗细为,颜色为蓝色
|
|||
|
|
Graphics g = this.CreateGraphics();
|
|||
|
|
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, 0, (this.LineWidth), e.ClipRectangle.Right, (this.LineWidth));
|
|||
|
|
|
|||
|
|
this.Height = (this.LineWidth * 2);
|
|||
|
|
g.Dispose();
|
|||
|
|
p.Dispose();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|