官网

http://www.hzhcontrols.com

前提

入行已经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自定义控件-管道阀门(工业)的更多相关文章

  1. (五十)c#Winform自定义控件-滑块

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...

  2. (三十)c#Winform自定义控件-文本框(三)

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  3. (二十)c#Winform自定义控件-有后退的窗体

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  4. (六十)c#Winform自定义控件-鼓风机(工业)

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...

  5. (八十)c#Winform自定义控件-分割线标签-HZHControls

    官网 http://www.hzhcontrols.com 前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kww ...

  6. (五十七)c#Winform自定义控件-传送带(工业)-HZHControls

    官网 http://www.hzhcontrols.com 前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kww ...

  7. Coding and Paper Letter(五十八)

    资源整理. 1 Coding: 1.支持TMS.WMTS标准瓦片下载,支持百度地图瓦片.高德地图瓦片.腾讯地图瓦片.天地图.ArcServer Rest瓦片.ArcServer本地缓存切片.geose ...

  8. .net开发笔记(十八) winform中的等待框

    winform中很多任务是需要在后台线程(或类似)中完成的,也就是说,经常容易涉及到UI界面与后台工作线程之间的交互.比如UI界面控制后台工作的执行(启动.暂停.停止等),后台工作进度在UI界面上的显 ...

  9. (十)c#Winform自定义控件-横向列表

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

随机推荐

  1. 12. 集合类Collection和Map

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  2. 原创:用node.js搭建本地服务模拟接口访问实现数据模拟

    前端开发中,数据模拟是必要的,这样就能等后台接口写完,我们直接把接口请求的url地址从本地数据模拟url换成后台真实地址就完成项目了.传参之类的都不用动. 之前网上找了很多类似于mock等感觉都不太实 ...

  3. 【iOS】打印方法名

    为了便于追踪程序运行过程,可以在日志打印方法名,示例代码如下: NSLog(@"%@", NSStringFromSelector(_cmd)); 结果如图所示: 此外,在多个中, ...

  4. TCP重置报文段及RST常见场景分析

    RST表示连接重置,用于关闭那些已经没有必要继续存在的连接.一般情况下表示异常关闭连接,区别与四次分手正常关闭连接. 产生RST的三个条件是: 目的地为某端口的SYN到达,然而在该端口上并没有正在监听 ...

  5. 泥瓦匠 5 年 Java 的成长感悟(下)

    继续<泥瓦匠 5 年 Java 的成长感悟(上)>,大致包括下面几点: 学技术的心态 学技术的学法 工作的心态 工作的硬技能 工作的软实力 听点雷子的民谣,我就安静地感概感概.上次说写的, ...

  6. javascript+jQuery补充

    一.jQuery事件绑定 <div class='c1'> <div> <div class='title'>菜单一</div> <div cla ...

  7. 【有容云】PPT | 容器与CICD的遇见

    编者注:本文为12月21日晚上8点有容云高级咨询顾问蒋运龙在腾讯课堂中演讲的PPT,本次课堂为有容云主办的线上直播Docker Live时代●Online Meetup-第四期:容器与CICD的遇见, ...

  8. SmartSql使用教程(4)——多库配置与使用

    一.引言 已经几个月没更新了.本来上一章的预告是准备写TypeHandler的相关特性的.但是在准备的时候.SmartSql的作者重构了一下TypeHandler,使得我一下子没搞懂TypeHandl ...

  9. PythonDay05

    第五章 今日内容 字典 字典 语法:{'key1':1,'key2':2} 注意:dict保存的数据不是按照我们添加进去的顺序保存的. 是按照hash表的顺序保存的. ⽽hash表 不是连续的. 所以 ...

  10. 又拍云叶靖:OpenResty 在又拍云存储中的应用

    2019 年 7 月 6 日,OpenResty 社区联合又拍云,举办 OpenResty × Open Talk 全国巡回沙龙·上海站,又拍云平台开发部负责人叶靖在活动上做了<OpenRest ...