(五十八)c#Winform自定义控件-管道阀门(工业)
官网
前提
入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。
GitHub:https://github.com/kwwwvagaa/NetWinformControl
码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
如果觉得写的还行,请点个 star 支持一下吧
欢迎前来交流探讨: 企鹅群568015492
麻烦博客下方点个【推荐】,谢谢
NuGet
- Install-Package HZH_Controls
目录
https://www.cnblogs.com/bfyx/p/11364884.html
用处及效果
准备工作
请先了解GDI+和三角函数
开始
添加一个类UCValve,继承UserControl
添加一个阀门显示样式枚举
- /// <summary>
- /// Enum ValveStyle
- /// </summary>
- public enum ValveStyle
- {
- /// <summary>
- /// 横向,开关在上方
- /// </summary>
- Horizontal_Top,
- /// <summary>
- /// 横向,开关在下方
- /// </summary>
- Horizontal_Bottom,
- /// <summary>
- /// 纵向,开关在左侧
- /// </summary>
- Vertical_Left,
- /// <summary>
- /// 纵向,开关在右侧
- /// </summary>
- Vertical_Right,
- }
添加一些属性
- /// <summary>
- /// The valve style
- /// </summary>
- private ValveStyle valveStyle = ValveStyle.Horizontal_Top;
- /// <summary>
- /// Gets or sets the valve style.
- /// </summary>
- /// <value>The valve style.</value>
- [Description("阀门样式"), Category("自定义")]
- public ValveStyle ValveStyle
- {
- get { return valveStyle; }
- set
- {
- valveStyle = value;
- Refresh();
- }
- }
- /// <summary>
- /// The valve color
- /// </summary>
- private Color valveColor = Color.FromArgb(, , );
- /// <summary>
- /// Gets or sets the color of the valve.
- /// </summary>
- /// <value>The color of the valve.</value>
- [Description("阀门颜色"), Category("自定义")]
- public Color ValveColor
- {
- get { return valveColor; }
- set
- {
- valveColor = value;
- Refresh();
- }
- }
- /// <summary>
- /// The switch color
- /// </summary>
- private Color switchColor = Color.FromArgb(, , );
- /// <summary>
- /// Gets or sets the color of the switch.
- /// </summary>
- /// <value>The color of the switch.</value>
- [Description("开关把手颜色"), Category("自定义")]
- public Color SwitchColor
- {
- get { return switchColor; }
- set
- {
- switchColor = value;
- Refresh();
- }
- }
- /// <summary>
- /// The axis color
- /// </summary>
- private Color axisColor = Color.FromArgb(, , );
- /// <summary>
- /// Gets or sets the color of the axis.
- /// </summary>
- /// <value>The color of the axis.</value>
- [Description("轴颜色"), Category("自定义")]
- public Color AxisColor
- {
- get { return axisColor; }
- set
- {
- axisColor = value;
- Refresh();
- }
- }
- /// <summary>
- /// The asis bottom color
- /// </summary>
- private Color asisBottomColor = Color.FromArgb(, , );
- /// <summary>
- /// Gets or sets the color of the asis bottom.
- /// </summary>
- /// <value>The color of the asis bottom.</value>
- [Description("轴底座颜色"), Category("自定义")]
- public Color AsisBottomColor
- {
- get { return asisBottomColor; }
- set { asisBottomColor = value; }
- }
- /// <summary>
- /// The opened
- /// </summary>
- private bool opened = true;
- /// <summary>
- /// Gets or sets a value indicating whether this <see cref="UCValve" /> is opened.
- /// </summary>
- /// <value><c>true</c> if opened; otherwise, <c>false</c>.</value>
- [Description("是否打开"), Category("自定义")]
- public bool Opened
- {
- get { return opened; }
- set
- {
- opened = value;
- Refresh();
- }
- }
- /// <summary>
- /// The liquid direction
- /// </summary>
- private LiquidDirection liquidDirection = LiquidDirection.Forward;
- /// <summary>
- /// Gets or sets the liquid direction.
- /// </summary>
- /// <value>The liquid direction.</value>
- [Description("液体流动方向"), Category("自定义")]
- public LiquidDirection LiquidDirection
- {
- get { return liquidDirection; }
- set
- {
- liquidDirection = value;
- if (value == Conduit.LiquidDirection.None)
- m_timer.Enabled = false;
- else
- m_timer.Enabled = true;
- Refresh();
- }
- }
- /// <summary>
- /// The liquid speed
- /// </summary>
- private int liquidSpeed = ;
- /// <summary>
- /// 液体流速,越小,速度越快Gets or sets the liquid speed.
- /// </summary>
- /// <value>The liquid speed.</value>
- [Description("液体流速,越小,速度越快"), Category("自定义")]
- public int LiquidSpeed
- {
- get { return liquidSpeed; }
- set
- {
- if (value <= )
- return;
- liquidSpeed = value;
- m_timer.Interval = value;
- }
- }
- /// <summary>
- /// The liquid color
- /// </summary>
- private Color liquidColor = Color.FromArgb(, , );
- /// <summary>
- /// Gets or sets the color of the liquid.
- /// </summary>
- /// <value>The color of the liquid.</value>
- [Description("液体颜色"), Category("自定义")]
- public Color LiquidColor
- {
- get { return liquidColor; }
- set
- {
- liquidColor = value;
- if (liquidDirection != Conduit.LiquidDirection.None)
- Refresh();
- }
- }
- /// <summary>
- /// The m timer
- /// </summary>
- Timer m_timer;
- /// <summary>
- /// The int line left
- /// </summary>
- int intLineLeft = ;
重绘
- protected override void OnPaint(PaintEventArgs e)
- {
- base.OnPaint(e);
- var g = e.Graphics;
- Rectangle rectGuan = Rectangle.Empty;//管道
- Rectangle rectJK1 = Rectangle.Empty;//接口1
- Rectangle rectJK2 = Rectangle.Empty;//接口2
- Rectangle rectZ = Rectangle.Empty;//轴
- GraphicsPath linePath = new GraphicsPath();//管道中心线
- GraphicsPath dzPath = new GraphicsPath();//轴底座
- GraphicsPath bsPath = new GraphicsPath();//开关把手
- switch (valveStyle)
- {
- case ValveStyle.Horizontal_Top:
- rectGuan = new Rectangle(, this.Height / , this.Width, this.Height / - this.Height / );
- rectJK1 = new Rectangle(this.Height / , rectGuan.Top - this.Height / , rectGuan.Height / , rectGuan.Height + this.Height / );
- rectJK2 = new Rectangle(rectGuan.Right - this.Height / - rectGuan.Height / , rectGuan.Top - this.Height / , rectGuan.Height / , rectGuan.Height + this.Height / );
- linePath.AddLine(new Point(rectGuan.Left - , rectGuan.Top + rectGuan.Height / ), new Point(rectGuan.Right + , rectGuan.Top + rectGuan.Height / ));
- rectZ = new Rectangle(rectGuan.Left + (rectGuan.Width - rectGuan.Height / ) / , , rectGuan.Height / , rectGuan.Top - );
- Point[] psTop = new Point[]
- {
- new Point(rectGuan.Left+(rectGuan.Width-rectGuan.Height/)/,rectGuan.Top- this.Height / - ),
- new Point(rectGuan.Right-(rectGuan.Width-rectGuan.Height/)/,rectGuan.Top- this.Height / - ),
- new Point(rectGuan.Right-(rectGuan.Width-rectGuan.Height)/,rectGuan.Top+ ),
- new Point(rectGuan.Left+(rectGuan.Width-rectGuan.Height)/,rectGuan.Top +),
- };
- dzPath.AddLines(psTop);
- dzPath.CloseAllFigures();
- if (opened)
- {
- bsPath.AddLine(rectGuan.Left + (rectGuan.Width - rectGuan.Height - ) / , + (rectGuan.Height / ) / , rectGuan.Left + (rectGuan.Width - rectGuan.Height - ) / + rectGuan.Height + , + (rectGuan.Height / ) / );
- }
- else
- {
- bsPath.AddLine(new Point(rectGuan.Left + rectGuan.Width / - , ), new Point(rectGuan.Left + rectGuan.Width / + , rectGuan.Height + ));
- }
- break;
- case ValveStyle.Horizontal_Bottom:
- rectGuan = new Rectangle(, this.Height / , this.Width, this.Height / - this.Height / );
- rectJK1 = new Rectangle(this.Height / , rectGuan.Top - this.Height / , rectGuan.Height / , rectGuan.Height + this.Height / );
- rectJK2 = new Rectangle(rectGuan.Right - this.Height / - rectGuan.Height / , rectGuan.Top - this.Height / , rectGuan.Height / , rectGuan.Height + this.Height / );
- linePath.AddLine(new Point(rectGuan.Left - , rectGuan.Top + rectGuan.Height / ), new Point(rectGuan.Right + , rectGuan.Top + rectGuan.Height / ));
- rectZ = new Rectangle(rectGuan.Left + (rectGuan.Width - rectGuan.Height / ) / , rectGuan.Bottom + , rectGuan.Height / , this.Height - - (rectGuan.Bottom + ));
- Point[] psBottom = new Point[]
- {
- new Point(rectGuan.Left+(rectGuan.Width-rectGuan.Height/)/,rectGuan.Bottom+ this.Height / + ),
- new Point(rectGuan.Right-(rectGuan.Width-rectGuan.Height/)/,rectGuan.Bottom+ this.Height / + ),
- new Point(rectGuan.Right-(rectGuan.Width-rectGuan.Height)/,rectGuan.Bottom- ),
- new Point(rectGuan.Left+(rectGuan.Width-rectGuan.Height)/,rectGuan.Bottom-),
- };
- dzPath.AddLines(psBottom);
- dzPath.CloseAllFigures();
- if (opened)
- {
- bsPath.AddLine(rectGuan.Left + (rectGuan.Width - rectGuan.Height - ) / , this.Height - ( + (rectGuan.Height / ) / ), rectGuan.Left + (rectGuan.Width - rectGuan.Height - ) / + rectGuan.Height + , this.Height - ( + (rectGuan.Height / ) / ));
- }
- else
- {
- bsPath.AddLine(new Point(rectGuan.Left + rectGuan.Width / - , this.Height - ), new Point(rectGuan.Left + rectGuan.Width / + , this.Height - (rectGuan.Height + )));
- }
- break;
- case ValveStyle.Vertical_Left:
- rectGuan = new Rectangle(this.Width / , , this.Width / - this.Width / , this.Height);
- rectJK1 = new Rectangle(, this.Width / , rectGuan.Width + this.Width / , rectGuan.Width / );
- rectJK2 = new Rectangle(, this.Height - this.Width / - rectGuan.Width / , rectGuan.Width + this.Width / , rectGuan.Width / );
- linePath.AddLine(new Point(rectGuan.Left + rectGuan.Width / , rectGuan.Top - ), new Point(rectGuan.Left + rectGuan.Width / , rectGuan.Bottom + ));
- rectZ = new Rectangle(rectGuan.Right, rectGuan.Top + (rectGuan.Height - rectGuan.Width / ) / , rectGuan.Right - , rectGuan.Width / );
- Point[] psLeft = new Point[]
- {
- new Point(rectGuan.Right+ this.Width / + ,rectGuan.Top + (rectGuan.Height - rectGuan.Width / ) / ),
- new Point(rectGuan.Right+ this.Width / + ,rectGuan.Top + (rectGuan.Height - rectGuan.Width / ) / +rectGuan.Width / ),
- new Point(rectGuan.Right-, rectGuan.Top +(rectGuan.Height-rectGuan.Width)/+rectGuan.Width),
- new Point(rectGuan.Right-, rectGuan.Top +(rectGuan.Height-rectGuan.Width)/),
- };
- dzPath.AddLines(psLeft);
- dzPath.CloseAllFigures();
- if (opened)
- {
- bsPath.AddLine(this.Width - ( + (rectGuan.Width / ) / ), rectGuan.Top + (rectGuan.Height - rectGuan.Width - ) / , this.Width - ( + (rectGuan.Width / ) / ), rectGuan.Top + (rectGuan.Height - rectGuan.Width - ) / + rectGuan.Width + );
- }
- else
- {
- bsPath.AddLine(new Point(this.Width - , rectGuan.Top + rectGuan.Height / - ), new Point(this.Width - (rectGuan.Width + ), rectGuan.Top + rectGuan.Height / + ));
- }
- break;
- case ValveStyle.Vertical_Right:
- rectGuan = new Rectangle(this.Width - this.Width / - (this.Width / - this.Width / ), , this.Width / - this.Width / , this.Height);
- rectJK1 = new Rectangle(this.Width - (rectGuan.Width + this.Width / ), this.Width / , rectGuan.Width + this.Width / , rectGuan.Width / );
- rectJK2 = new Rectangle(this.Width - (rectGuan.Width + this.Width / ), this.Height - this.Width / - rectGuan.Width / , rectGuan.Width + this.Width / , rectGuan.Width / );
- linePath.AddLine(new Point(rectGuan.Left + rectGuan.Width / , rectGuan.Top - ), new Point(rectGuan.Left + rectGuan.Width / , rectGuan.Bottom + ));
- rectZ = new Rectangle(, rectGuan.Top + (rectGuan.Height - rectGuan.Width / ) / , rectGuan.Left-, rectGuan.Width / );
- Point[] psRight = new Point[]
- {
- new Point(rectGuan.Left- (this.Width / + ) ,rectGuan.Top + (rectGuan.Height - rectGuan.Width / ) / ),
- new Point(rectGuan.Left-( this.Width / + ) ,rectGuan.Top + (rectGuan.Height - rectGuan.Width / ) / +rectGuan.Width / ),
- new Point(rectGuan.Left+, rectGuan.Top +(rectGuan.Height-rectGuan.Width)/+rectGuan.Width),
- new Point(rectGuan.Left+, rectGuan.Top +(rectGuan.Height-rectGuan.Width)/),
- };
- dzPath.AddLines(psRight);
- dzPath.CloseAllFigures();
- if (opened)
- {
- bsPath.AddLine( ( + (rectGuan.Width / ) / ), rectGuan.Top + (rectGuan.Height - rectGuan.Width - ) / , ( + (rectGuan.Width / ) / ), rectGuan.Top + (rectGuan.Height - rectGuan.Width - ) / + rectGuan.Width + );
- }
- else
- {
- bsPath.AddLine(new Point( , rectGuan.Top + rectGuan.Height / - ), new Point( (rectGuan.Width + ), rectGuan.Top + rectGuan.Height / + ));
- }
- break;
- }
- //管道
- g.FillRectangle(new SolidBrush(valveColor), rectGuan);
- //接口
- g.FillRectangle(new SolidBrush(valveColor), rectJK1);
- g.FillRectangle(new SolidBrush(Color.FromArgb(, Color.White)), rectJK1);
- g.FillRectangle(new SolidBrush(valveColor), rectJK2);
- g.FillRectangle(new SolidBrush(Color.FromArgb(, Color.White)), rectJK2);
- //高亮
- int intCount = (valveStyle.ToString().StartsWith("H") ? rectGuan.Height : rectGuan.Width) / / ;
- for (int i = ; i < intCount; i++)
- {
- int _penWidth = (valveStyle.ToString().StartsWith("H") ? rectGuan.Height : rectGuan.Width) / - * i;
- if (_penWidth <= )
- _penWidth = ;
- g.DrawPath(new Pen(new SolidBrush(Color.FromArgb(, Color.White.R, Color.White.G, Color.White.B)), _penWidth), linePath);
- if (_penWidth == )
- break;
- }
- g.SetGDIHigh();
- //轴
- g.FillRectangle(new SolidBrush(axisColor), rectZ);
- //阀门底座
- g.FillPath(new SolidBrush(asisBottomColor), dzPath);
- g.FillPath(new SolidBrush(Color.FromArgb(, Color.White)), dzPath);
- //把手
- g.DrawPath(new Pen(new SolidBrush(switchColor), (valveStyle.ToString().StartsWith("H") ? rectGuan.Height : rectGuan.Width) / ), bsPath);
- //液体流动
- if (opened)
- {
- Pen p = new Pen(new SolidBrush(liquidColor), );
- p.DashPattern = new float[] { , };
- p.DashOffset = intLineLeft * (LiquidDirection == Conduit.LiquidDirection.Forward ? - : );
- g.DrawPath(p, linePath);
- }
- }
全部代码
- // ***********************************************************************
- // Assembly : HZH_Controls
- // Created : 2019-09-06
- //
- // ***********************************************************************
- // <copyright file="UCValve.cs">
- // Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
- // </copyright>
- //
- // 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 HZH_Controls.Controls.Conduit;
- using System.ComponentModel;
- namespace HZH_Controls.Controls
- {
- /// <summary>
- /// Class UCValve.
- /// Implements the <see cref="System.Windows.Forms.UserControl" />
- /// </summary>
- /// <seealso cref="System.Windows.Forms.UserControl" />
- public class UCValve : UserControl
- {
- /// <summary>
- /// The valve style
- /// </summary>
- private ValveStyle valveStyle = ValveStyle.Horizontal_Top;
- /// <summary>
- /// Gets or sets the valve style.
- /// </summary>
- /// <value>The valve style.</value>
- [Description("阀门样式"), Category("自定义")]
- public ValveStyle ValveStyle
- {
- get { return valveStyle; }
- set
- {
- valveStyle = value;
- Refresh();
- }
- }
- /// <summary>
- /// The valve color
- /// </summary>
- private Color valveColor = Color.FromArgb(, , );
- /// <summary>
- /// Gets or sets the color of the valve.
- /// </summary>
- /// <value>The color of the valve.</value>
- [Description("阀门颜色"), Category("自定义")]
- public Color ValveColor
- {
- get { return valveColor; }
- set
- {
- valveColor = value;
- Refresh();
- }
- }
- /// <summary>
- /// The switch color
- /// </summary>
- private Color switchColor = Color.FromArgb(, , );
- /// <summary>
- /// Gets or sets the color of the switch.
- /// </summary>
- /// <value>The color of the switch.</value>
- [Description("开关把手颜色"), Category("自定义")]
- public Color SwitchColor
- {
- get { return switchColor; }
- set
- {
- switchColor = value;
- Refresh();
- }
- }
- /// <summary>
- /// The axis color
- /// </summary>
- private Color axisColor = Color.FromArgb(, , );
- /// <summary>
- /// Gets or sets the color of the axis.
- /// </summary>
- /// <value>The color of the axis.</value>
- [Description("轴颜色"), Category("自定义")]
- public Color AxisColor
- {
- get { return axisColor; }
- set
- {
- axisColor = value;
- Refresh();
- }
- }
- /// <summary>
- /// The asis bottom color
- /// </summary>
- private Color asisBottomColor = Color.FromArgb(, , );
- /// <summary>
- /// Gets or sets the color of the asis bottom.
- /// </summary>
- /// <value>The color of the asis bottom.</value>
- [Description("轴底座颜色"), Category("自定义")]
- public Color AsisBottomColor
- {
- get { return asisBottomColor; }
- set { asisBottomColor = value; }
- }
- /// <summary>
- /// The opened
- /// </summary>
- private bool opened = true;
- /// <summary>
- /// Gets or sets a value indicating whether this <see cref="UCValve" /> is opened.
- /// </summary>
- /// <value><c>true</c> if opened; otherwise, <c>false</c>.</value>
- [Description("是否打开"), Category("自定义")]
- public bool Opened
- {
- get { return opened; }
- set
- {
- opened = value;
- Refresh();
- }
- }
- /// <summary>
- /// The liquid direction
- /// </summary>
- private LiquidDirection liquidDirection = LiquidDirection.Forward;
- /// <summary>
- /// Gets or sets the liquid direction.
- /// </summary>
- /// <value>The liquid direction.</value>
- [Description("液体流动方向"), Category("自定义")]
- public LiquidDirection LiquidDirection
- {
- get { return liquidDirection; }
- set
- {
- liquidDirection = value;
- if (value == Conduit.LiquidDirection.None)
- m_timer.Enabled = false;
- else
- m_timer.Enabled = true;
- Refresh();
- }
- }
- /// <summary>
- /// The liquid speed
- /// </summary>
- private int liquidSpeed = ;
- /// <summary>
- /// 液体流速,越小,速度越快Gets or sets the liquid speed.
- /// </summary>
- /// <value>The liquid speed.</value>
- [Description("液体流速,越小,速度越快"), Category("自定义")]
- public int LiquidSpeed
- {
- get { return liquidSpeed; }
- set
- {
- if (value <= )
- return;
- liquidSpeed = value;
- m_timer.Interval = value;
- }
- }
- /// <summary>
- /// The liquid color
- /// </summary>
- private Color liquidColor = Color.FromArgb(, , );
- /// <summary>
- /// Gets or sets the color of the liquid.
- /// </summary>
- /// <value>The color of the liquid.</value>
- [Description("液体颜色"), Category("自定义")]
- public Color LiquidColor
- {
- get { return liquidColor; }
- set
- {
- liquidColor = value;
- if (liquidDirection != Conduit.LiquidDirection.None)
- Refresh();
- }
- }
- /// <summary>
- /// The m timer
- /// </summary>
- Timer m_timer;
- /// <summary>
- /// The int line left
- /// </summary>
- int intLineLeft = ;
- /// <summary>
- /// Initializes a new instance of the <see cref="UCValve" /> class.
- /// </summary>
- public UCValve()
- {
- 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.Size = new Size(, );
- m_timer = new Timer();
- m_timer.Interval = ;
- m_timer.Tick += timer_Tick;
- m_timer.Enabled = true;
- }
- /// <summary>
- /// Handles the Tick event of the timer control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
- void timer_Tick(object sender, EventArgs e)
- {
- intLineLeft += ;
- if (intLineLeft > )
- intLineLeft = ;
- Refresh();
- }
- /// <summary>
- /// 引发 <see cref="E:System.Windows.Forms.Control.Paint" /> 事件。
- /// </summary>
- /// <param name="e">包含事件数据的 <see cref="T:System.Windows.Forms.PaintEventArgs" />。</param>
- protected override void OnPaint(PaintEventArgs e)
- {
- base.OnPaint(e);
- var g = e.Graphics;
- Rectangle rectGuan = Rectangle.Empty;//管道
- Rectangle rectJK1 = Rectangle.Empty;//接口1
- Rectangle rectJK2 = Rectangle.Empty;//接口2
- Rectangle rectZ = Rectangle.Empty;//轴
- GraphicsPath linePath = new GraphicsPath();//管道中心线
- GraphicsPath dzPath = new GraphicsPath();//轴底座
- GraphicsPath bsPath = new GraphicsPath();//开关把手
- switch (valveStyle)
- {
- case ValveStyle.Horizontal_Top:
- rectGuan = new Rectangle(, this.Height / , this.Width, this.Height / - this.Height / );
- rectJK1 = new Rectangle(this.Height / , rectGuan.Top - this.Height / , rectGuan.Height / , rectGuan.Height + this.Height / );
- rectJK2 = new Rectangle(rectGuan.Right - this.Height / - rectGuan.Height / , rectGuan.Top - this.Height / , rectGuan.Height / , rectGuan.Height + this.Height / );
- linePath.AddLine(new Point(rectGuan.Left - , rectGuan.Top + rectGuan.Height / ), new Point(rectGuan.Right + , rectGuan.Top + rectGuan.Height / ));
- rectZ = new Rectangle(rectGuan.Left + (rectGuan.Width - rectGuan.Height / ) / , , rectGuan.Height / , rectGuan.Top - );
- Point[] psTop = new Point[]
- {
- new Point(rectGuan.Left+(rectGuan.Width-rectGuan.Height/)/,rectGuan.Top- this.Height / - ),
- new Point(rectGuan.Right-(rectGuan.Width-rectGuan.Height/)/,rectGuan.Top- this.Height / - ),
- new Point(rectGuan.Right-(rectGuan.Width-rectGuan.Height)/,rectGuan.Top+ ),
- new Point(rectGuan.Left+(rectGuan.Width-rectGuan.Height)/,rectGuan.Top +),
- };
- dzPath.AddLines(psTop);
- dzPath.CloseAllFigures();
- if (opened)
- {
- bsPath.AddLine(rectGuan.Left + (rectGuan.Width - rectGuan.Height - ) / , + (rectGuan.Height / ) / , rectGuan.Left + (rectGuan.Width - rectGuan.Height - ) / + rectGuan.Height + , + (rectGuan.Height / ) / );
- }
- else
- {
- bsPath.AddLine(new Point(rectGuan.Left + rectGuan.Width / - , ), new Point(rectGuan.Left + rectGuan.Width / + , rectGuan.Height + ));
- }
- break;
- case ValveStyle.Horizontal_Bottom:
- rectGuan = new Rectangle(, this.Height / , this.Width, this.Height / - this.Height / );
- rectJK1 = new Rectangle(this.Height / , rectGuan.Top - this.Height / , rectGuan.Height / , rectGuan.Height + this.Height / );
- rectJK2 = new Rectangle(rectGuan.Right - this.Height / - rectGuan.Height / , rectGuan.Top - this.Height / , rectGuan.Height / , rectGuan.Height + this.Height / );
- linePath.AddLine(new Point(rectGuan.Left - , rectGuan.Top + rectGuan.Height / ), new Point(rectGuan.Right + , rectGuan.Top + rectGuan.Height / ));
- rectZ = new Rectangle(rectGuan.Left + (rectGuan.Width - rectGuan.Height / ) / , rectGuan.Bottom + , rectGuan.Height / , this.Height - - (rectGuan.Bottom + ));
- Point[] psBottom = new Point[]
- {
- new Point(rectGuan.Left+(rectGuan.Width-rectGuan.Height/)/,rectGuan.Bottom+ this.Height / + ),
- new Point(rectGuan.Right-(rectGuan.Width-rectGuan.Height/)/,rectGuan.Bottom+ this.Height / + ),
- new Point(rectGuan.Right-(rectGuan.Width-rectGuan.Height)/,rectGuan.Bottom- ),
- new Point(rectGuan.Left+(rectGuan.Width-rectGuan.Height)/,rectGuan.Bottom-),
- };
- dzPath.AddLines(psBottom);
- dzPath.CloseAllFigures();
- if (opened)
- {
- bsPath.AddLine(rectGuan.Left + (rectGuan.Width - rectGuan.Height - ) / , this.Height - ( + (rectGuan.Height / ) / ), rectGuan.Left + (rectGuan.Width - rectGuan.Height - ) / + rectGuan.Height + , this.Height - ( + (rectGuan.Height / ) / ));
- }
- else
- {
- bsPath.AddLine(new Point(rectGuan.Left + rectGuan.Width / - , this.Height - ), new Point(rectGuan.Left + rectGuan.Width / + , this.Height - (rectGuan.Height + )));
- }
- break;
- case ValveStyle.Vertical_Left:
- rectGuan = new Rectangle(this.Width / , , this.Width / - this.Width / , this.Height);
- rectJK1 = new Rectangle(, this.Width / , rectGuan.Width + this.Width / , rectGuan.Width / );
- rectJK2 = new Rectangle(, this.Height - this.Width / - rectGuan.Width / , rectGuan.Width + this.Width / , rectGuan.Width / );
- linePath.AddLine(new Point(rectGuan.Left + rectGuan.Width / , rectGuan.Top - ), new Point(rectGuan.Left + rectGuan.Width / , rectGuan.Bottom + ));
- rectZ = new Rectangle(rectGuan.Right, rectGuan.Top + (rectGuan.Height - rectGuan.Width / ) / , rectGuan.Right - , rectGuan.Width / );
- Point[] psLeft = new Point[]
- {
- new Point(rectGuan.Right+ this.Width / + ,rectGuan.Top + (rectGuan.Height - rectGuan.Width / ) / ),
- new Point(rectGuan.Right+ this.Width / + ,rectGuan.Top + (rectGuan.Height - rectGuan.Width / ) / +rectGuan.Width / ),
- new Point(rectGuan.Right-, rectGuan.Top +(rectGuan.Height-rectGuan.Width)/+rectGuan.Width),
- new Point(rectGuan.Right-, rectGuan.Top +(rectGuan.Height-rectGuan.Width)/),
- };
- dzPath.AddLines(psLeft);
- dzPath.CloseAllFigures();
- if (opened)
- {
- bsPath.AddLine(this.Width - ( + (rectGuan.Width / ) / ), rectGuan.Top + (rectGuan.Height - rectGuan.Width - ) / , this.Width - ( + (rectGuan.Width / ) / ), rectGuan.Top + (rectGuan.Height - rectGuan.Width - ) / + rectGuan.Width + );
- }
- else
- {
- bsPath.AddLine(new Point(this.Width - , rectGuan.Top + rectGuan.Height / - ), new Point(this.Width - (rectGuan.Width + ), rectGuan.Top + rectGuan.Height / + ));
- }
- break;
- case ValveStyle.Vertical_Right:
- rectGuan = new Rectangle(this.Width - this.Width / - (this.Width / - this.Width / ), , this.Width / - this.Width / , this.Height);
- rectJK1 = new Rectangle(this.Width - (rectGuan.Width + this.Width / ), this.Width / , rectGuan.Width + this.Width / , rectGuan.Width / );
- rectJK2 = new Rectangle(this.Width - (rectGuan.Width + this.Width / ), this.Height - this.Width / - rectGuan.Width / , rectGuan.Width + this.Width / , rectGuan.Width / );
- linePath.AddLine(new Point(rectGuan.Left + rectGuan.Width / , rectGuan.Top - ), new Point(rectGuan.Left + rectGuan.Width / , rectGuan.Bottom + ));
- rectZ = new Rectangle(, rectGuan.Top + (rectGuan.Height - rectGuan.Width / ) / , rectGuan.Left-, rectGuan.Width / );
- Point[] psRight = new Point[]
- {
- new Point(rectGuan.Left- (this.Width / + ) ,rectGuan.Top + (rectGuan.Height - rectGuan.Width / ) / ),
- new Point(rectGuan.Left-( this.Width / + ) ,rectGuan.Top + (rectGuan.Height - rectGuan.Width / ) / +rectGuan.Width / ),
- new Point(rectGuan.Left+, rectGuan.Top +(rectGuan.Height-rectGuan.Width)/+rectGuan.Width),
- new Point(rectGuan.Left+, rectGuan.Top +(rectGuan.Height-rectGuan.Width)/),
- };
- dzPath.AddLines(psRight);
- dzPath.CloseAllFigures();
- if (opened)
- {
- bsPath.AddLine( ( + (rectGuan.Width / ) / ), rectGuan.Top + (rectGuan.Height - rectGuan.Width - ) / , ( + (rectGuan.Width / ) / ), rectGuan.Top + (rectGuan.Height - rectGuan.Width - ) / + rectGuan.Width + );
- }
- else
- {
- bsPath.AddLine(new Point( , rectGuan.Top + rectGuan.Height / - ), new Point( (rectGuan.Width + ), rectGuan.Top + rectGuan.Height / + ));
- }
- break;
- }
- //管道
- g.FillRectangle(new SolidBrush(valveColor), rectGuan);
- //接口
- g.FillRectangle(new SolidBrush(valveColor), rectJK1);
- g.FillRectangle(new SolidBrush(Color.FromArgb(, Color.White)), rectJK1);
- g.FillRectangle(new SolidBrush(valveColor), rectJK2);
- g.FillRectangle(new SolidBrush(Color.FromArgb(, Color.White)), rectJK2);
- //高亮
- int intCount = (valveStyle.ToString().StartsWith("H") ? rectGuan.Height : rectGuan.Width) / / ;
- for (int i = ; i < intCount; i++)
- {
- int _penWidth = (valveStyle.ToString().StartsWith("H") ? rectGuan.Height : rectGuan.Width) / - * i;
- if (_penWidth <= )
- _penWidth = ;
- g.DrawPath(new Pen(new SolidBrush(Color.FromArgb(, Color.White.R, Color.White.G, Color.White.B)), _penWidth), linePath);
- if (_penWidth == )
- break;
- }
- g.SetGDIHigh();
- //轴
- g.FillRectangle(new SolidBrush(axisColor), rectZ);
- //阀门底座
- g.FillPath(new SolidBrush(asisBottomColor), dzPath);
- g.FillPath(new SolidBrush(Color.FromArgb(, Color.White)), dzPath);
- //把手
- g.DrawPath(new Pen(new SolidBrush(switchColor), (valveStyle.ToString().StartsWith("H") ? rectGuan.Height : rectGuan.Width) / ), bsPath);
- //液体流动
- if (opened)
- {
- Pen p = new Pen(new SolidBrush(liquidColor), );
- p.DashPattern = new float[] { , };
- p.DashOffset = intLineLeft * (LiquidDirection == Conduit.LiquidDirection.Forward ? - : );
- g.DrawPath(p, linePath);
- }
- }
- }
- /// <summary>
- /// Enum ValveStyle
- /// </summary>
- public enum ValveStyle
- {
- /// <summary>
- /// 横向,开关在上方
- /// </summary>
- Horizontal_Top,
- /// <summary>
- /// 横向,开关在下方
- /// </summary>
- Horizontal_Bottom,
- /// <summary>
- /// 纵向,开关在左侧
- /// </summary>
- Vertical_Left,
- /// <summary>
- /// 纵向,开关在右侧
- /// </summary>
- Vertical_Right,
- }
- }
最后的话
如果你喜欢的话,请到 https://gitee.com/kwwwvagaa/net_winform_custom_control 点个星星吧
(五十八)c#Winform自定义控件-管道阀门(工业)的更多相关文章
- (五十)c#Winform自定义控件-滑块
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...
- (三十)c#Winform自定义控件-文本框(三)
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- (二十)c#Winform自定义控件-有后退的窗体
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- (六十)c#Winform自定义控件-鼓风机(工业)
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...
- (八十)c#Winform自定义控件-分割线标签-HZHControls
官网 http://www.hzhcontrols.com 前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kww ...
- (五十七)c#Winform自定义控件-传送带(工业)-HZHControls
官网 http://www.hzhcontrols.com 前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kww ...
- Coding and Paper Letter(五十八)
资源整理. 1 Coding: 1.支持TMS.WMTS标准瓦片下载,支持百度地图瓦片.高德地图瓦片.腾讯地图瓦片.天地图.ArcServer Rest瓦片.ArcServer本地缓存切片.geose ...
- .net开发笔记(十八) winform中的等待框
winform中很多任务是需要在后台线程(或类似)中完成的,也就是说,经常容易涉及到UI界面与后台工作线程之间的交互.比如UI界面控制后台工作的执行(启动.暂停.停止等),后台工作进度在UI界面上的显 ...
- (十)c#Winform自定义控件-横向列表
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
随机推荐
- PyCharm字体大小调整
1.点击左上角File----settings----keymap----------搜索increase,选中,increase font size--------再选择enter mouse sh ...
- ASP.NET Core Web Api之JWT刷新Token(三)
前言 如题,本节我们进入JWT最后一节内容,JWT本质上就是从身份认证服务器获取访问令牌,继而对于用户后续可访问受保护资源,但是关键问题是:访问令牌的生命周期到底设置成多久呢?见过一些使用JWT的童鞋 ...
- 4. 源码分析---SOFARPC服务端暴露
服务端的示例 我们首先贴上我们的服务端的示例: public static void main(String[] args) { ServerConfig serverConfig = new Ser ...
- 1. 源码分析---SOFARPC可扩展的机制SPI
这几天离职在家,正好没事可以疯狂的输出一下,本来想写DUBBO的源码解析的,但是发现写DUBBO源码的太多了,所以找一个写的不那么多的框架,所以就选中SOFARPC这个框架了. SOFARPC是蚂蚁金 ...
- MySQL操作命令梳理(2)
一.表操作 在mysql运维操作中会经常使用到alter这个修改表的命令,alter tables允许修改一个现有表的结构,比如增加或删除列.创造或消去索引.改变现有列的类型.或重新命名列或表本身,也 ...
- Intent 使用详解
极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android Intent 是一个消息传递对象,主要用于组建之间的通讯,例如:启动Activit ...
- Mybatis获取代理对象
mybatis-config.xml里标签可以放置多个environment,这里可以切换test和develop数据源 databaseIdProvider提供多种数据库,在xml映射文件里选择da ...
- Vue项目中使用better-scroll
当 better-scroll 遇见 Vue 在我们日常的移动端项目开发中,处理滚动列表是再常见不过的需求了. 以滴滴为例,可以是这样竖向滚动的列表,如图所示: 也可以是横向滚动的导航栏,如图所示 ...
- alluxio2.0特性-预览
项目地址 https://github.com/Alluxio/alluxio/tree/branch-2.0-preview 2.0版本-构思和设计 支持超大规模数据工作负载 Alluxio作为计算 ...
- 弹性盒子---CSS3布局方式
1.弹性盒子/伸缩盒子 如果要使用弹性盒子属性,首先要将父级元素变成弹性盒子 Flex-direction 设置伸缩盒子的内部元素的排列方式 Row 从左到右安行排列 Column 从上到下按 ...