// *********************************************************************** // Assembly : HZH_Controls // Created : 2019-09-04 // // *********************************************************************** // // Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com // // // Blog: https://www.cnblogs.com/bfyx // GitHub:https://github.com/kwwwvagaa/NetWinformControl // gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git // // If you use this code, please keep this note. // *********************************************************************** using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing; using System.Drawing.Drawing2D; using System.ComponentModel; namespace HZH_Controls.Controls { /// /// Class UCConduit. /// Implements the /// /// public class UCConduit : UserControl { /// /// The conduit style /// private ConduitStyle conduitStyle = ConduitStyle.Horizontal_None_None; /// /// Gets or sets the conduit style. /// /// The conduit style. [Description("样式"), Category("自定义")] public ConduitStyle ConduitStyle { get { return conduitStyle; } set { string strOld = conduitStyle.ToString().Substring(0, 1); string strNew = value.ToString().Substring(0, 1); conduitStyle = value; if (strOld != strNew) { this.Size = new Size(this.Size.Height, this.Size.Width); } Refresh(); } } /// /// The conduit color /// private Color conduitColor = Color.FromArgb(255, 77, 59); [Description("颜色"), Category("自定义")] /// /// Gets or sets the color of the conduit. /// /// The color of the conduit. public Color ConduitColor { get { return conduitColor; } set { conduitColor = value; Refresh(); } } /// /// The liquid color /// private Color liquidColor = Color.FromArgb(3, 169, 243); /// /// Gets or sets the color of the liquid. /// /// The color of the liquid. [Description("液体颜色"), Category("自定义")] public Color LiquidColor { get { return liquidColor; } set { liquidColor = value; if (liquidDirection != LiquidDirection.None) Refresh(); } } /// /// The liquid direction /// private LiquidDirection liquidDirection = LiquidDirection.Forward; /// /// Gets or sets the liquid direction. /// /// The liquid direction. [Description("液体流动方向"), Category("自定义")] public LiquidDirection LiquidDirection { get { return liquidDirection; } set { liquidDirection = value; if (value == LiquidDirection.None) m_timer.Enabled = false; else m_timer.Enabled = true; Refresh(); } } /// /// The liquid speed /// private int liquidSpeed = 100; /// /// 液体流速,越小,速度越快Gets or sets the liquid speed. /// /// The liquid speed. [Description("液体流速,越小,速度越快"), Category("自定义")] public int LiquidSpeed { get { return liquidSpeed; } set { if (value <= 0) return; liquidSpeed = value; m_timer.Interval = value; } } /// /// The conduit width /// int conduitWidth = 50; /// /// Gets or sets the width of the conduit. /// /// The width of the conduit. [Description("管道宽度,当ConduitStyle的值是Horizontal_Tilt_Up,Horizontal_Tilt_Down,Vertical_Tilt_Left,Vertical_Tilt_Right时有效,其他时候将根据管道大小使用自动宽度"), Category("自定义")] public int ConduitWidth { get { return conduitWidth; } set { conduitWidth = value; Refresh(); } } /// /// The int pen width /// int intPenWidth = 0; /// /// The int line left /// int intLineLeft = 0; /// /// The m timer /// Timer m_timer; /// /// Initializes a new instance of the class. /// public UCConduit() { this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.DoubleBuffer, true); this.SetStyle(ControlStyles.ResizeRedraw, true); this.SetStyle(ControlStyles.Selectable, true); this.SetStyle(ControlStyles.SupportsTransparentBackColor, true); this.SetStyle(ControlStyles.UserPaint, true); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.SizeChanged += UCConduit_SizeChanged; this.Size = new Size(200, 50); m_timer = new Timer(); m_timer.Interval = 100; m_timer.Tick += timer_Tick; m_timer.Enabled = true; } /// /// Handles the Tick event of the timer control. /// /// The source of the event. /// The instance containing the event data. void timer_Tick(object sender, EventArgs e) { intLineLeft += 2; if (intLineLeft > 12) intLineLeft = 0; Refresh(); } /// /// Handles the SizeChanged event of the UCConduit control. /// /// The source of the event. /// The instance containing the event data. void UCConduit_SizeChanged(object sender, EventArgs e) { intPenWidth = conduitStyle.ToString().StartsWith("H") ? this.Height : this.Width; } /// /// 引发 事件。 /// /// 包含事件数据的 。 protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; List lstArcs = new List(); GraphicsPath path = new GraphicsPath(); GraphicsPath linePath = new GraphicsPath(); List tileLine = new List(); switch (conduitStyle) { #region H English:H case ConduitStyle.Horizontal_None_None: path.AddLines(new PointF[] { new PointF(0, 0), new PointF(this.ClientRectangle.Right, 0), new PointF(this.ClientRectangle.Right, this.Height), new PointF(0, this.Height) }); path.CloseAllFigures(); linePath.AddLine(0, this.Height / 2, this.Width, this.Height / 2); break; case ConduitStyle.Horizontal_Up_None: path.AddLines(new PointF[] { new PointF(0, 0), new PointF(this.ClientRectangle.Right, 0), new PointF(this.ClientRectangle.Right, this.Height), new PointF(0+intPenWidth, this.Height) }); path.AddArc(new Rectangle(0, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), 90, 90); path.CloseAllFigures(); linePath.AddArc(new Rectangle(intPenWidth / 2 + 1, -1 * intPenWidth / 2 - 1, intPenWidth, intPenWidth), 181, -91); linePath.AddLine(intPenWidth, this.Height / 2, this.Width, this.Height / 2); lstArcs.Add(new ArcEntity() { rect = new Rectangle(0, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), startAngle = 90, sweepAngle = 90 }); break; case ConduitStyle.Horizontal_Down_None: path.AddLines(new PointF[] { new PointF(intPenWidth, 0), new PointF(this.ClientRectangle.Right, 0), new PointF(this.ClientRectangle.Right, this.Height), new PointF(0, this.Height) }); path.AddArc(new Rectangle(0, -1, intPenWidth * 2, intPenWidth * 2), 180, 90); path.CloseAllFigures(); linePath.AddArc(new Rectangle(intPenWidth / 2 + 1, this.Height / 2, intPenWidth, intPenWidth), 179, 91); linePath.AddLine(intPenWidth + 1, this.Height / 2, this.Width, this.Height / 2); lstArcs.Add(new ArcEntity() { rect = new Rectangle(0, -1, intPenWidth * 2, intPenWidth * 2), startAngle = 180, sweepAngle = 90 }); break; case ConduitStyle.Horizontal_None_Up: path.AddLines(new PointF[] { new PointF(this.ClientRectangle.Right-intPenWidth, this.Height), new PointF(0, this.Height), new PointF(0, 0), new PointF(this.ClientRectangle.Right-intPenWidth, 0) }); path.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), 0, 90); path.CloseAllFigures(); linePath.AddLine(0, this.Height / 2, this.Width - intPenWidth, this.Height / 2); linePath.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth - intPenWidth / 2 - 1, -1 * intPenWidth / 2 - 1, intPenWidth, intPenWidth), 91, -91); lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), startAngle = 0, sweepAngle = 90 }); break; case ConduitStyle.Horizontal_None_Down: path.AddLines(new PointF[] { new PointF(this.ClientRectangle.Right, this.Height), new PointF(0, this.Height), new PointF(0, 0), new PointF(this.ClientRectangle.Right-intPenWidth, 0) }); path.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, -1, intPenWidth * 2, intPenWidth * 2), 270, 90); path.CloseAllFigures(); linePath.AddLine(0, this.Height / 2, this.Width - intPenWidth - 1, this.Height / 2); linePath.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth - intPenWidth / 2 - 1, intPenWidth / 2, intPenWidth, intPenWidth), 269, 91); lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, -1, intPenWidth * 2, intPenWidth * 2), startAngle = 270, sweepAngle = 90 }); break; case ConduitStyle.Horizontal_Down_Up: path.AddLine(new Point(intPenWidth, 0), new Point(this.Width, 0)); path.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), 0, 90); path.AddLine(new Point(this.Width - intPenWidth, this.Height), new Point(0, this.Height)); path.AddArc(new Rectangle(0, -1, intPenWidth * 2, intPenWidth * 2), 180, 90); path.CloseAllFigures(); linePath.AddArc(new Rectangle(intPenWidth / 2 + 1, this.Height / 2, intPenWidth, intPenWidth), 179, 91); //linePath.AddLine(intPenWidth, this.Height / 2, this.Width - intPenWidth, this.Height / 2); linePath.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth - intPenWidth / 2 - 1, -1 * intPenWidth / 2 - 1, intPenWidth, intPenWidth), 91, -91); lstArcs.Add(new ArcEntity() { rect = new Rectangle(0, -1, intPenWidth * 2, intPenWidth * 2), startAngle = 180, sweepAngle = 90 }); lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), startAngle = 0, sweepAngle = 90 }); break; case ConduitStyle.Horizontal_Up_Down: path.AddLine(new Point(0, 0), new Point(this.Width - intPenWidth, 0)); path.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, -1, intPenWidth * 2, intPenWidth * 2), 270, 90); path.AddLine(new Point(this.Width, this.Height), new Point(intPenWidth, this.Height)); path.AddArc(new Rectangle(0, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), 90, 90); path.CloseAllFigures(); linePath.AddArc(new Rectangle(intPenWidth / 2 + 1, -1 * intPenWidth / 2 - 1, intPenWidth, intPenWidth), 181, -91); linePath.AddLine(intPenWidth, this.Height / 2, this.Width - intPenWidth - 1, this.Height / 2); linePath.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth - intPenWidth / 2 - 1, intPenWidth / 2, intPenWidth, intPenWidth), 269, 91); lstArcs.Add(new ArcEntity() { rect = new Rectangle(0, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), startAngle = 90, sweepAngle = 90 }); lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, -1, intPenWidth * 2, intPenWidth * 2), startAngle = 270, sweepAngle = 90 }); break; case ConduitStyle.Horizontal_Up_Up: path.AddLine(new Point(0, 0), new Point(this.Width, 0)); path.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), 0, 90); path.AddLine(new Point(this.Width - intPenWidth, this.Height), new Point(intPenWidth, this.Height)); path.AddArc(new Rectangle(0, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), 90, 90); path.CloseAllFigures(); linePath.AddArc(new Rectangle(intPenWidth / 2 + 1, -1 * intPenWidth / 2 - 1, intPenWidth, intPenWidth), 181, -91); //linePath.AddLine(intPenWidth, this.Height / 2, this.Width - intPenWidth, this.Height / 2); linePath.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth - intPenWidth / 2 - 1, -1 * intPenWidth / 2 - 1, intPenWidth, intPenWidth), 91, -91); lstArcs.Add(new ArcEntity() { rect = new Rectangle(0, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), startAngle = 90, sweepAngle = 90 }); lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), startAngle = 0, sweepAngle = 90 }); break; case ConduitStyle.Horizontal_Down_Down: path.AddLine(new Point(intPenWidth, 0), new Point(this.Width - intPenWidth, 0)); path.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, -1, intPenWidth * 2, intPenWidth * 2), 270, 90); path.AddLine(new Point(this.Width, this.Height), new Point(0, this.Height)); path.AddArc(new Rectangle(0, -1, intPenWidth * 2, intPenWidth * 2), 180, 90); path.CloseAllFigures(); linePath.AddArc(new Rectangle(intPenWidth / 2 + 1, this.Height / 2, intPenWidth, intPenWidth), 179, 91); linePath.AddLine(intPenWidth + 1, this.Height / 2, this.Width - intPenWidth - 1, this.Height / 2); linePath.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth - intPenWidth / 2 - 1, intPenWidth / 2, intPenWidth, intPenWidth), 269, 91); lstArcs.Add(new ArcEntity() { rect = new Rectangle(0, -1, intPenWidth * 2, intPenWidth * 2), startAngle = 180, sweepAngle = 90 }); lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, -1, intPenWidth * 2, intPenWidth * 2), startAngle = 270, sweepAngle = 90 }); break; case ConduitStyle.Horizontal_Tilt_Up: double angleUp = Math.Atan((this.ClientRectangle.Height - conduitWidth) / (double)this.ClientRectangle.Width); angleUp = angleUp / Math.PI * 180f; path.AddArc(new Rectangle(this.ClientRectangle.Left - conduitWidth, this.ClientRectangle.Bottom - conduitWidth * 2, conduitWidth * 2, conduitWidth * 2), 90, -1 * (float)angleUp); path.AddLine(new Point(this.ClientRectangle.Right, this.ClientRectangle.Top + conduitWidth), new Point(this.ClientRectangle.Right, this.ClientRectangle.Top)); path.AddArc(new Rectangle(this.ClientRectangle.Right - conduitWidth, this.ClientRectangle.Top, conduitWidth * 2, conduitWidth * 2), 270, -1 * (float)angleUp); path.AddLine(new Point(this.ClientRectangle.Left, this.ClientRectangle.Bottom - conduitWidth), new Point(this.ClientRectangle.Left, this.ClientRectangle.Bottom)); path.CloseAllFigures(); linePath.AddArc(new Rectangle(this.ClientRectangle.Right - conduitWidth / 2, this.ClientRectangle.Top + conduitWidth / 2, conduitWidth, conduitWidth), 270, -1 * (float)angleUp); linePath.AddArc(new Rectangle(this.ClientRectangle.Left - conduitWidth / 2, this.ClientRectangle.Bottom - 1 - conduitWidth - conduitWidth / 2, conduitWidth, conduitWidth), 95 - (float)angleUp, (float)angleUp + 5); lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Left - conduitWidth, this.ClientRectangle.Bottom - conduitWidth * 2, conduitWidth * 2, conduitWidth * 2), startAngle = 90, sweepAngle = -1 * (float)angleUp }); lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - conduitWidth, this.ClientRectangle.Top, conduitWidth * 2, conduitWidth * 2), startAngle = 270, sweepAngle = -1 * (float)angleUp }); tileLine.Add(new Point[] { new Point((int)(this.ClientRectangle.Right+1 - Math.Sin(Math.PI * (angleUp / 180.00F)) * conduitWidth),(int)( this.ClientRectangle.Top + conduitWidth - Math.Cos(Math.PI * (angleUp / 180.00F)) * conduitWidth)), new Point(this.ClientRectangle.Left,this.ClientRectangle.Bottom-conduitWidth-1) }); tileLine.Add(new Point[] { new Point((int)(this.ClientRectangle.Left+1 + Math.Sin(Math.PI * (angleUp / 180.00F)) * conduitWidth),(int)( this.ClientRectangle.Bottom - conduitWidth + Math.Cos(Math.PI * (angleUp / 180.00F)) * conduitWidth)), new Point(this.ClientRectangle.Right,this.ClientRectangle.Top+conduitWidth) }); break; case ConduitStyle.Horizontal_Tilt_Down: double angleDown = Math.Atan((this.ClientRectangle.Height - conduitWidth) / (double)this.ClientRectangle.Width); angleDown = angleDown / Math.PI * 180f; path.AddArc(new Rectangle(this.ClientRectangle.Left - conduitWidth, this.ClientRectangle.Top, conduitWidth * 2, conduitWidth * 2), 270, (float)angleDown); path.AddLine(new Point(this.ClientRectangle.Right, this.ClientRectangle.Bottom - conduitWidth), new Point(this.ClientRectangle.Right, this.ClientRectangle.Bottom)); path.AddArc(new Rectangle(this.ClientRectangle.Right - conduitWidth, this.ClientRectangle.Bottom - conduitWidth * 2, conduitWidth * 2, conduitWidth * 2), 90, (float)angleDown); path.AddLine(new Point(this.ClientRectangle.Left, this.ClientRectangle.Top + conduitWidth), new Point(this.ClientRectangle.Left, this.ClientRectangle.Top)); path.CloseAllFigures(); linePath.AddArc(new Rectangle(this.ClientRectangle.Left - conduitWidth / 2, this.ClientRectangle.Top + conduitWidth / 2, conduitWidth, conduitWidth), 265, (float)angleDown + 5); linePath.AddArc(new Rectangle(this.ClientRectangle.Right - conduitWidth / 2, this.ClientRectangle.Bottom - conduitWidth - conduitWidth / 2 - 1, conduitWidth, conduitWidth), 90 + (float)angleDown, -1 * (float)angleDown - 5); lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Left - conduitWidth, this.ClientRectangle.Top, conduitWidth * 2, conduitWidth * 2), startAngle = 270, sweepAngle = (float)angleDown }); lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - conduitWidth, this.ClientRectangle.Bottom - conduitWidth * 2, conduitWidth * 2, conduitWidth * 2), startAngle = 90, sweepAngle = (float)angleDown }); tileLine.Add(new Point[] { new Point((int)(this.ClientRectangle.Left + Math.Sin(Math.PI * (angleDown / 180.00F)) * conduitWidth),(int)( this.ClientRectangle.Top + conduitWidth - Math.Cos(Math.PI * (angleDown / 180.00F)) * conduitWidth)), new Point(this.ClientRectangle.Right-1,this.ClientRectangle.Bottom-conduitWidth-1) }); tileLine.Add(new Point[] { new Point((int)(this.ClientRectangle.Right - Math.Sin(Math.PI * (angleDown / 180.00F)) * conduitWidth),(int)( this.ClientRectangle.Bottom - conduitWidth + Math.Cos(Math.PI * (angleDown / 180.00F)) * conduitWidth)), new Point(this.ClientRectangle.Left,this.ClientRectangle.Top+conduitWidth) }); break; #endregion #region V English:V case ConduitStyle.Vertical_None_None: path.AddLines(new PointF[] { new PointF(0, 0), new PointF(this.ClientRectangle.Right, 0), new PointF(this.ClientRectangle.Right, this.Height), new PointF(0, this.Height) }); path.CloseAllFigures(); linePath.AddLine(this.Width / 2, 0, this.Width / 2, this.Height); break; case ConduitStyle.Vertical_Left_None: path.AddLines(new PointF[] { new PointF(this.ClientRectangle.Right, intPenWidth), new PointF(this.ClientRectangle.Right, this.Height), new PointF(0, this.Height), new PointF(0, 0) }); path.AddArc(new Rectangle(-1 * intPenWidth, 0, intPenWidth * 2, intPenWidth * 2), 270, 90); path.CloseAllFigures(); linePath.AddArc(new Rectangle(-1 * intPenWidth / 2 - 1, intPenWidth / 2 + 1, intPenWidth, intPenWidth), 269, 91); linePath.AddLine(intPenWidth / 2, intPenWidth, intPenWidth / 2, this.Height); lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1 * intPenWidth, 0, intPenWidth * 2, intPenWidth * 2), startAngle = 270, sweepAngle = 90 }); break; case ConduitStyle.Vertical_Right_None: path.AddLines(new PointF[] { new PointF(this.ClientRectangle.Right, 0), new PointF(this.ClientRectangle.Right, this.Height), new PointF(0, this.Height), new PointF(0, intPenWidth) }); path.AddArc(new Rectangle(-1, 0, intPenWidth * 2, intPenWidth * 2), 180, 90); path.CloseAllFigures(); linePath.AddArc(new Rectangle(intPenWidth / 2, intPenWidth / 2 + 1, intPenWidth, intPenWidth), 271, -91); linePath.AddLine(intPenWidth / 2, intPenWidth + 1, intPenWidth / 2, this.Height); lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1, 0, intPenWidth * 2, intPenWidth * 2), startAngle = 180, sweepAngle = 90 }); break; case ConduitStyle.Vertical_None_Left: path.AddLines(new PointF[] { new PointF(0, this.Height), new PointF(0, 0), new PointF(this.ClientRectangle.Right, 0), new PointF(this.ClientRectangle.Right, this.Height-intPenWidth), }); path.AddArc(new Rectangle(-1 * intPenWidth, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), 0, 90); path.CloseAllFigures(); linePath.AddLine(this.Width / 2, 0, this.Width / 2, this.Height - intPenWidth); linePath.AddArc(new Rectangle(-1 * intPenWidth / 2 - 1, this.Height - intPenWidth - intPenWidth / 2 - 1, intPenWidth, intPenWidth), -1, 91); lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1 * intPenWidth, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), startAngle = 0, sweepAngle = 90 }); break; case ConduitStyle.Vertical_None_Right: path.AddLines(new PointF[] { new PointF(0, this.Height-intPenWidth), new PointF(0, 0), new PointF(this.ClientRectangle.Right, 0), new PointF(this.ClientRectangle.Right, this.Height), }); path.AddArc(new Rectangle(-1, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), 90, 90); path.CloseAllFigures(); linePath.AddLine(this.Width / 2, 0, this.Width / 2, this.Height - intPenWidth - 1); linePath.AddArc(new Rectangle(intPenWidth / 2, this.Height - intPenWidth - intPenWidth / 2 - 1, intPenWidth, intPenWidth), 181, -91); lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), startAngle = 90, sweepAngle = 90 }); break; case ConduitStyle.Vertical_Left_Right: path.AddLine(this.Width, intPenWidth, this.Width, this.Height); path.AddArc(new Rectangle(-1, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), 90, 90); path.AddLine(0, this.Height - intPenWidth, 0, 0); path.AddArc(new Rectangle(-1 * intPenWidth, 0, intPenWidth * 2, intPenWidth * 2), 270, 90); path.CloseAllFigures(); linePath.AddArc(new Rectangle(-1 * intPenWidth / 2 - 1, intPenWidth / 2 + 1, intPenWidth, intPenWidth), 269, 91); //linePath.AddLine(intPenWidth / 2, intPenWidth, intPenWidth / 2, this.Height - intPenWidth); linePath.AddArc(new Rectangle(intPenWidth / 2, this.Height - intPenWidth - intPenWidth / 2 - 1, intPenWidth, intPenWidth), 181, -91); lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1 * intPenWidth, 0, intPenWidth * 2, intPenWidth * 2), startAngle = 270, sweepAngle = 90 }); lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), startAngle = 90, sweepAngle = 90 }); break; case ConduitStyle.Vertical_Right_Left: path.AddLine(this.Width, 0, this.Width, this.Height - intPenWidth); path.AddArc(new Rectangle(-1 * intPenWidth, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), 0, 90); path.AddLine(0, this.Height, 0, intPenWidth); path.AddArc(new Rectangle(-1, 0, intPenWidth * 2, intPenWidth * 2), 180, 90); path.CloseAllFigures(); linePath.AddArc(new Rectangle(intPenWidth / 2, intPenWidth / 2 + 1, intPenWidth, intPenWidth), 271, -91); //linePath.AddLine(intPenWidth / 2, intPenWidth, intPenWidth / 2, this.Height - intPenWidth); linePath.AddArc(new Rectangle(-1 * intPenWidth / 2 - 1, this.Height - intPenWidth - intPenWidth / 2 - 1, intPenWidth, intPenWidth), -1, 91); lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1, 0, intPenWidth * 2, intPenWidth * 2), startAngle = 180, sweepAngle = 90 }); lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1 * intPenWidth, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), startAngle = 0, sweepAngle = 90 }); break; case ConduitStyle.Vertical_Left_Left: path.AddLine(this.Width, intPenWidth, this.Width, this.Height - intPenWidth); path.AddArc(new Rectangle(-1 * intPenWidth, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), 0, 90); path.AddLine(0, this.Height, 0, 0); path.AddArc(new Rectangle(-1 * intPenWidth, 0, intPenWidth * 2, intPenWidth * 2), 270, 90); path.CloseAllFigures(); linePath.AddArc(new Rectangle(-1 * intPenWidth / 2 - 1, intPenWidth / 2 + 1, intPenWidth, intPenWidth), 269, 91); //linePath.AddLine(intPenWidth / 2, intPenWidth, intPenWidth / 2, this.Height - intPenWidth); linePath.AddArc(new Rectangle(-1 * intPenWidth / 2 - 1, this.Height - intPenWidth - intPenWidth / 2 - 1, intPenWidth, intPenWidth), -1, 91); lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1 * intPenWidth, 0, intPenWidth * 2, intPenWidth * 2), startAngle = 270, sweepAngle = 90 }); lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1 * intPenWidth, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), startAngle = 0, sweepAngle = 90 }); break; case ConduitStyle.Vertical_Right_Right: path.AddLine(this.Width, 0, this.Width, this.Height); path.AddArc(new Rectangle(-1, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), 90, 90); path.AddLine(0, this.Height - intPenWidth, 0, intPenWidth); path.AddArc(new Rectangle(-1, 0, intPenWidth * 2, intPenWidth * 2), 180, 90); path.CloseAllFigures(); linePath.AddArc(new Rectangle(intPenWidth / 2, intPenWidth / 2 + 1, intPenWidth, intPenWidth), 271, -91); //linePath.AddLine(intPenWidth / 2, intPenWidth, intPenWidth / 2, this.Height - intPenWidth); linePath.AddArc(new Rectangle(intPenWidth / 2, this.Height - intPenWidth - intPenWidth / 2 - 1, intPenWidth, intPenWidth), 180, -91); lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1, 0, intPenWidth * 2, intPenWidth * 2), startAngle = 180, sweepAngle = 90 }); lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), startAngle = 90, sweepAngle = 90 }); break; case ConduitStyle.Vertical_Tilt_Left: double angleLeft = Math.Atan((this.ClientRectangle.Width - conduitWidth) / (double)this.ClientRectangle.Height); angleLeft = angleLeft / Math.PI * 180f; path.AddArc(new Rectangle(this.ClientRectangle.Left - 1, ClientRectangle.Top - conduitWidth, conduitWidth * 2, conduitWidth * 2), 180, -1 * (float)angleLeft); path.AddLine(new Point(this.ClientRectangle.Right - conduitWidth, this.ClientRectangle.Bottom), new Point(this.ClientRectangle.Right, this.ClientRectangle.Bottom)); path.AddArc(new Rectangle(this.ClientRectangle.Right - conduitWidth * 2, this.ClientRectangle.Bottom - conduitWidth, conduitWidth * 2, conduitWidth * 2), 0, -1 * (float)angleLeft); path.AddLine(new Point(this.ClientRectangle.Left + conduitWidth, this.ClientRectangle.Top), new Point(this.ClientRectangle.Left, this.ClientRectangle.Top)); path.CloseAllFigures(); linePath.AddArc(new Rectangle(this.ClientRectangle.Left + conduitWidth / 2, this.ClientRectangle.Top - conduitWidth / 2, conduitWidth, conduitWidth), 185, -1 * (float)angleLeft - 5); linePath.AddArc(new Rectangle(this.ClientRectangle.Right - conduitWidth - conduitWidth / 2, this.ClientRectangle.Bottom - conduitWidth / 2, conduitWidth, conduitWidth), -1 * (float)angleLeft, (float)angleLeft); lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Left - 1, ClientRectangle.Top - conduitWidth, conduitWidth * 2, conduitWidth * 2), startAngle = 180, sweepAngle = -1 * (float)angleLeft }); lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - conduitWidth * 2, this.ClientRectangle.Bottom - conduitWidth, conduitWidth * 2, conduitWidth * 2), startAngle = 0, sweepAngle = -1 * (float)angleLeft }); tileLine.Add(new Point[] { new Point((int)(this.ClientRectangle.Left + conduitWidth),this.ClientRectangle.Top), new Point((int)(this.ClientRectangle.Right-conduitWidth+Math.Cos(Math.PI * (angleLeft / 180.00F)) * conduitWidth),(int)(this.ClientRectangle.Bottom-Math.Sin(Math.PI * (angleLeft / 180.00F)) * conduitWidth)) }); tileLine.Add(new Point[] { new Point((int)(this.ClientRectangle.Left-1+conduitWidth-Math.Cos(Math.PI * (angleLeft / 180.00F)) * conduitWidth),(int)(this.ClientRectangle.Top+Math.Sin(Math.PI * (angleLeft / 180.00F)) * conduitWidth)), new Point(this.ClientRectangle.Right-conduitWidth,this.ClientRectangle.Bottom) }); break; case ConduitStyle.Vertical_Tilt_Right: double angleRight = Math.Atan((this.ClientRectangle.Width - conduitWidth) / (double)this.ClientRectangle.Height); angleRight = angleRight / Math.PI * 180f; path.AddArc(new Rectangle(this.ClientRectangle.Right - conduitWidth * 2, ClientRectangle.Top - conduitWidth, conduitWidth * 2, conduitWidth * 2), 0, (float)angleRight); path.AddLine(new Point(this.ClientRectangle.Left + conduitWidth, this.ClientRectangle.Bottom), new Point(this.ClientRectangle.Left, this.ClientRectangle.Bottom)); path.AddArc(new Rectangle(this.ClientRectangle.Left - 1, this.ClientRectangle.Bottom - conduitWidth, conduitWidth * 2, conduitWidth * 2), 180, (float)angleRight); path.AddLine(new Point(this.ClientRectangle.Right - conduitWidth, this.ClientRectangle.Top), new Point(this.ClientRectangle.Right, this.ClientRectangle.Top)); path.CloseAllFigures(); linePath.AddArc(new Rectangle(this.ClientRectangle.Right - conduitWidth - conduitWidth / 2, this.ClientRectangle.Top - conduitWidth / 2, conduitWidth, conduitWidth), -5, (float)angleRight + 5); linePath.AddArc(new Rectangle(this.ClientRectangle.Left + conduitWidth / 2, this.ClientRectangle.Bottom - conduitWidth / 2, conduitWidth, conduitWidth), 180 + (float)angleRight, -1 * (float)angleRight); lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - conduitWidth * 2, ClientRectangle.Top - conduitWidth, conduitWidth * 2, conduitWidth * 2), startAngle = 0, sweepAngle = (float)angleRight }); lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Left - 1, this.ClientRectangle.Bottom - conduitWidth, conduitWidth * 2, conduitWidth * 2), startAngle = 180, sweepAngle = (float)angleRight }); tileLine.Add(new Point[] { new Point((int)(this.ClientRectangle.Right - conduitWidth),this.ClientRectangle.Top), new Point((int)(this.ClientRectangle.Left + conduitWidth - Math.Cos(Math.PI * (angleRight / 180.00F)) * conduitWidth),(int)(this.ClientRectangle.Bottom-Math.Sin(Math.PI * (angleRight / 180.00F)) * conduitWidth)) }); tileLine.Add(new Point[] { new Point((int)(this.ClientRectangle.Right - conduitWidth+Math.Cos(Math.PI * (angleRight / 180.00F)) * conduitWidth),(int)(this.ClientRectangle.Top+Math.Sin(Math.PI * (angleRight / 180.00F)) * conduitWidth)), new Point(this.ClientRectangle.Left + conduitWidth,this.ClientRectangle.Bottom) }); break; #endregion } base.Region = new Region(path); g.FillPath(new SolidBrush(conduitColor), path); //渐变色 int _intPenWidth = intPenWidth; if (conduitStyle.ToString().Contains("Tilt")) { _intPenWidth = conduitWidth; } int intCount = _intPenWidth / 2 / 4; for (int i = 0; i < intCount; i++) { int _penWidth = _intPenWidth / 2 - 4 * i; if (_penWidth <= 0) _penWidth = 1; g.DrawPath(new Pen(new SolidBrush(Color.FromArgb(40, Color.White.R, Color.White.G, Color.White.B)), _penWidth), linePath); if (_penWidth == 1) break; } g.SetGDIHigh(); //使用抗锯齿画圆角 foreach (var item in lstArcs) { g.DrawArc(new Pen(new SolidBrush(this.BackColor)), item.rect, item.startAngle, item.sweepAngle); } if (tileLine.Count > 0) { foreach (var item in tileLine) { g.DrawLine(new Pen(new SolidBrush(this.BackColor)), item[0], item[1]); } } //液体流动 if (LiquidDirection != LiquidDirection.None) { Pen p = new Pen(new SolidBrush(liquidColor), 4); p.DashPattern = new float[] { 6, 6 }; p.DashOffset = intLineLeft * (LiquidDirection == LiquidDirection.Forward ? -1 : 1); g.DrawPath(p, linePath); } } /// /// Class ArcEntity. /// class ArcEntity { /// /// Gets or sets the rect. /// /// The rect. public Rectangle rect { get; set; } /// /// Gets or sets the start angle. /// /// The start angle. public float startAngle { get; set; } /// /// Gets or sets the sweep angle. /// /// The sweep angle. public float sweepAngle { get; set; } } } /// /// Enum LiquidDirection /// public enum LiquidDirection { /// /// The none /// None, /// /// The forward /// Forward, /// /// The backward /// Backward } /// /// 管道样式Enum ConduitStyle /// public enum ConduitStyle { /// /// 直线 The horizontal none none /// Horizontal_None_None, /// /// 左上The horizontal up none /// Horizontal_Up_None, /// /// 左下The horizontal down none /// Horizontal_Down_None, /// /// 右上The horizontal none up /// Horizontal_None_Up, /// /// 右下The horizontal none down /// Horizontal_None_Down, /// /// 左下右上The horizontal down up /// Horizontal_Down_Up, /// /// 左上右下The horizontal up down /// Horizontal_Up_Down, /// /// 左上,右上The horizontal up up /// Horizontal_Up_Up, /// /// 左下右下The horizontal down down /// Horizontal_Down_Down, /// /// 向上倾斜The horizontal tilt up /// Horizontal_Tilt_Up, /// /// 向下倾斜The horizontal tilt down /// Horizontal_Tilt_Down, /// /// 竖线The vertical none none /// Vertical_None_None, /// /// 上左The vertical left none /// Vertical_Left_None, /// /// 上右The vertical right none /// Vertical_Right_None, /// /// 下左The vertical none left /// Vertical_None_Left, /// /// 下右The vertical none right /// Vertical_None_Right, /// /// 上左下右The vertical left right /// Vertical_Left_Right, /// /// 上右下左The vertical right left /// Vertical_Right_Left, /// /// 上左下左The vertical left left /// Vertical_Left_Left, /// /// 上右下右The vertical right left /// Vertical_Right_Right, /// /// 向左倾斜The vertical tilt /// Vertical_Tilt_Left, /// /// 向右倾斜The vertical tilt right /// Vertical_Tilt_Right } }