官网

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. Drools规则引擎-如果判断某个对象中的集合是否包含指定的值

    规则引擎集合相关处理 在实际生产过程中,有很多关于集合的处理场景,比如一个Fact对象中包含有一个集合,而需要判断该集合是否包含某个值.而Drools规则引擎也提供了多种处理方式,比如通过from.c ...

  2. python的enumerate lambda isinstance filter函数

    0x01:filter(function,iterable) filter()函数用于过滤序列,过滤掉不符合条件的元素,返回由符合条件元素组成的新列表. 接收两个参数,第一个为函数,第二个为序列(可迭 ...

  3. MyBatis 简介与入门

    简介 什么是 MyBatis ? MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.My ...

  4. redis缓存介绍以及常见问题浅析

    # 没缓存的日子: 对于web来说,是用户量和访问量支持项目技术的更迭和前进.随着服务用户提升.可能会出现一下的一些状况: 页面并发量和访问量并不多,mysql足以支撑自己逻辑业务的发展.那么其实可以 ...

  5. 单元测试python unittest

    记录自己学习单元测试框架的一篇博客 菜鸟的学习之路比较艰辛到处找资料一把辛酸泪啊 1.首先是创建一个类里面设计一些简单的函数方便写用例: 原谅我蹩脚的英文直接用拼音命名了 : 2.接着就是创建用例文件 ...

  6. 【Java笔记】【Java核心技术卷1】chapter3 D4变量

    package chapter3; public class D4变量 { public static final int BBB=100; //类常量 public static void main ...

  7. hadoop学习(七)----mapReduce原理以及操作过程

    前面我们使用HDFS进行了相关的操作,也了解了HDFS的原理和机制,有了分布式文件系统我们如何去处理文件呢,这就的提到hadoop的第二个组成部分-MapReduce. MapReduce充分借鉴了分 ...

  8. Unity的赛车游戏实现思路

    unity目前版本实现赛车的技术方案主要有3种: 1.wheelCollider,设置motorTorque.brakeTorque.steerAngle来实现车子的推动和转弯,优点是上手简单,而且很 ...

  9. 【原创实践】U大师启动安装windows XP

    1:使用U大师3.0版制作启动U盘,拷贝windows xp或者win7的原版安装iso(zh-hans_windows_xp_professional_with_service_pack_3_x86 ...

  10. 小白系统篇-windows 系统安装

    现阶段装系统的方法基本有几种1.硬盘安装2.光驱安装3.PE(u盘即可)安装 现在比较主流方便的用pe安装,所以我们这边就说一下PE安装系统的方法 首先我们了解下系统镜像,也就是你装系统所需得到文件( ...