using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; using Microsoft.Drawing; namespace Microsoft.Windows.Forms { /// /// 虚拟直线控件 /// public class UILine : UIControl { private bool m_Horizontal = true; /// /// 获取或设置是否水平线.true表示水平线,false表示垂直线 /// public virtual bool Horizontal { get { return this.m_Horizontal; } set { if (value != this.m_Horizontal) { this.m_Horizontal = value; base.Invalidate(); } } } private int m_LineWidth = 1; /// /// 获取或设置直线宽度 /// public virtual int LineWidth { get { return this.m_LineWidth; } set { if (value != this.m_LineWidth) { this.m_LineWidth = value; this.Invalidate(); } } } private Color m_LineColor = DefaultTheme.DarkDarkBorderColor; /// /// 获取或设置直线颜色 /// public virtual Color LineColor { get { return this.m_LineColor; } set { if (value != this.m_LineColor) { this.m_LineColor = value; this.Invalidate(); } } } private BlendStyle m_LineBlendStyle = BlendStyle.Solid; /// /// 渲染方式 /// public virtual BlendStyle LineBlendStyle { get { return this.m_LineBlendStyle; } set { if (value != this.m_LineBlendStyle) { this.m_LineBlendStyle = value; base.Invalidate(); } } } private DashStyle m_LineDashStyle = DashStyle.Solid; /// /// 获取或设置直线的虚线样式 /// public virtual DashStyle LineDashStyle { get { return this.m_LineDashStyle; } set { if (value != this.m_LineDashStyle) { this.m_LineDashStyle = value; this.Invalidate(); } } } /// /// 渲染控件 /// /// 数据 protected override void RenderSelf(PaintEventArgs e) { //准备 Graphics g = e.Graphics; Rectangle rect = RectangleEx.Subtract(this.ClientRectangle, this.Padding); //计算起点终点 Point begin, end; if (this.Horizontal) { begin = new Point(rect.X, (rect.Y + rect.Bottom) / 2); end = new Point(rect.Right, begin.Y); } else { begin = new Point((rect.X + rect.Right) / 2, rect.Y); end = new Point(begin.X, rect.Bottom); } //渲染 this.Sprite.LineWidth = this.LineWidth; this.Sprite.LineColor = this.LineColor; this.Sprite.LineBlendStyle = this.LineBlendStyle; this.Sprite.LineDashStyle = this.LineDashStyle; base.Sprite.BeginRender(g); base.Sprite.RenderLine(begin, end); base.Sprite.EndRender(); } } }