(五十八)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 ...
随机推荐
- 关于java飞机躲炮弹的一些对象说明(带源码)
1.飞机躲炮弹的各种实体类都需要一个画笔将他们画出来 (GameObject) import java.awt.*; public void drawSelf(Graphics g){ g.drawI ...
- 警惕!CAF效应导致PCB漏电
最近碰到一个PCB漏电的问题,起因是一款低功耗产品,本来整机uA级别的电流,常温老化使用了一段时间后发现其功耗上升,个别样机功耗甚至达到了mA级别.仔细排除了元器件问题,最终发现了一个5V电压点,在产 ...
- 有容云:上车 | 听老司机谈Docker安全合规建设
编者注: 本文根据7月19日DockOne社群分享内容整理而成,分享嘉宾蒋运龙,有容云高级咨询顾问,一个IT的老兵,十年来混迹于存储.三网融合.多屏互动.智能穿戴.第三方支付.Docker等行业:经历 ...
- JS 自执行函数
由于自己js基础知识薄弱,很多js的知识还没有掌握,所以接下来会经常写一些关于js基础知识的博客,也算给自己提个醒吧. js自执行函数,听到这个名字,首先会联想到函数.接下来,我来定义一个函数: fu ...
- Python 与数据库交互
安装:pip3 install pymysql 引入模块在python3里:from pymysql import * 使用步骤:1.创建Connection对象,用于建立与数据库的连接,创建对象调用 ...
- 12、面向对象的思想(OOP)
面向对象与面向过程 1.都是解决问题的思维方式,都是代码的组织的方式: 2.解决简单的问题可以使用面向过程: 3.解决复杂的问题建议使用面向对象,微观处理依旧会使用面向过程. 对象的进化史(数据管理的 ...
- 2月11日 阿里巴巴Java开发手册 读后感
该手册分为几个部分: 印象深刻的几点: (五)集合处理 2.[强制]ArrayList的subList结果不可强转成ArrayList,否则会抛出ClassCastException 异常:java. ...
- Liunx查看后1000行的命令以及查看中间部分
linux 如何显示一个文件的某几行(中间几行) [一]从第3000行开始,显示1000行.即显示3000~3999行 cat filename | tail -n +3000 | head -n 1 ...
- python数据类型图解
- 使用Graphlab参加Kaggle比赛(2017-08-20 发布于知乎)
之前用学生证在graphlab上申了一年的graphlab使用权(华盛顿大学机器学习课程需要)然后今天突然想到完全可以用这个东东来参加kaggle. 下午参考了一篇教程,把notebook上面的写好了 ...