mirror of
https://github.com/eggplantlwj/VisionEdit.git
synced 2026-03-24 08:46:35 +08:00
1、优化LOG显示与引用
2、添加PMA工具,工具内容待完善 3、修复流程树显示 4、添加开源项目,优化UI空间 5、其他BUG更改
This commit is contained in:
@@ -0,0 +1,343 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : HZH_Controls
|
||||
// Created : 2019-09-10
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="UCArrow.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 System.ComponentModel;
|
||||
|
||||
namespace HZH_Controls.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UCArrow.
|
||||
/// Implements the <see cref="System.Windows.Forms.UserControl" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Windows.Forms.UserControl" />
|
||||
public class UCArrow : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// The arrow color
|
||||
/// </summary>
|
||||
private Color arrowColor = Color.FromArgb(255, 77, 59);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the arrow.
|
||||
/// </summary>
|
||||
/// <value>The color of the arrow.</value>
|
||||
[Description("箭头颜色"), Category("自定义")]
|
||||
public Color ArrowColor
|
||||
{
|
||||
get { return arrowColor; }
|
||||
set
|
||||
{
|
||||
arrowColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The border color
|
||||
/// </summary>
|
||||
private Color? borderColor = null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the border.
|
||||
/// </summary>
|
||||
/// <value>The color of the border.</value>
|
||||
[Description("箭头边框颜色,为空则无边框"), Category("自定义")]
|
||||
public Color? BorderColor
|
||||
{
|
||||
get { return borderColor; }
|
||||
set
|
||||
{
|
||||
borderColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The direction
|
||||
/// </summary>
|
||||
private ArrowDirection direction = ArrowDirection.Right;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the direction.
|
||||
/// </summary>
|
||||
/// <value>The direction.</value>
|
||||
[Description("箭头方向"), Category("自定义")]
|
||||
public ArrowDirection Direction
|
||||
{
|
||||
get { return direction; }
|
||||
set
|
||||
{
|
||||
direction = value;
|
||||
ResetPath();
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取或设置控件显示的文字的字体。
|
||||
/// </summary>
|
||||
/// <value>The font.</value>
|
||||
/// <PermissionSet>
|
||||
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||||
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
||||
/// <IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||||
/// </PermissionSet>
|
||||
public override Font Font
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Font;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.Font = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取或设置控件的前景色。
|
||||
/// </summary>
|
||||
/// <value>The color of the fore.</value>
|
||||
/// <PermissionSet>
|
||||
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||||
/// </PermissionSet>
|
||||
public override Color ForeColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.ForeColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.ForeColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The text
|
||||
/// </summary>
|
||||
private string text;
|
||||
/// <summary>
|
||||
/// Gets or sets the text.
|
||||
/// </summary>
|
||||
/// <value>The text.</value>
|
||||
[Bindable(true)]
|
||||
[Browsable(true)]
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
|
||||
[EditorBrowsable(EditorBrowsableState.Always)]
|
||||
[Localizable(true)]
|
||||
[Description("箭头文字"), Category("自定义")]
|
||||
public override string Text
|
||||
{
|
||||
get
|
||||
{
|
||||
return text;
|
||||
}
|
||||
set
|
||||
{
|
||||
text = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The m path
|
||||
/// </summary>
|
||||
GraphicsPath m_path;
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UCArrow" /> class.
|
||||
/// </summary>
|
||||
public UCArrow()
|
||||
{
|
||||
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.ForeColor = Color.White;
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.SizeChanged += UCArrow_SizeChanged;
|
||||
this.Size = new Size(100, 50);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the SizeChanged event of the UCArrow 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 UCArrow_SizeChanged(object sender, EventArgs e)
|
||||
{
|
||||
ResetPath();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the path.
|
||||
/// </summary>
|
||||
private void ResetPath()
|
||||
{
|
||||
Point[] ps = null;
|
||||
switch (direction)
|
||||
{
|
||||
case ArrowDirection.Left:
|
||||
ps = new Point[]
|
||||
{
|
||||
new Point(0,this.Height/2),
|
||||
new Point(40,0),
|
||||
new Point(40,this.Height/4),
|
||||
new Point(this.Width-1,this.Height/4),
|
||||
new Point(this.Width-1,this.Height-this.Height/4),
|
||||
new Point(40,this.Height-this.Height/4),
|
||||
new Point(40,this.Height),
|
||||
new Point(0,this.Height/2)
|
||||
};
|
||||
break;
|
||||
case ArrowDirection.Right:
|
||||
ps = new Point[]
|
||||
{
|
||||
new Point(0,this.Height/4),
|
||||
new Point(this.Width-40,this.Height/4),
|
||||
new Point(this.Width-40,0),
|
||||
new Point(this.Width-1,this.Height/2),
|
||||
new Point(this.Width-40,this.Height),
|
||||
new Point(this.Width-40,this.Height-this.Height/4),
|
||||
new Point(0,this.Height-this.Height/4),
|
||||
new Point(0,this.Height/4)
|
||||
};
|
||||
break;
|
||||
case ArrowDirection.Top:
|
||||
ps = new Point[]
|
||||
{
|
||||
new Point(this.Width/2,0),
|
||||
new Point(this.Width,40),
|
||||
new Point(this.Width-this.Width/4,40),
|
||||
new Point(this.Width-this.Width/4,this.Height-1),
|
||||
new Point(this.Width/4,this.Height-1),
|
||||
new Point(this.Width/4,40),
|
||||
new Point(0,40),
|
||||
new Point(this.Width/2,0),
|
||||
};
|
||||
break;
|
||||
case ArrowDirection.Bottom:
|
||||
ps = new Point[]
|
||||
{
|
||||
new Point(this.Width-this.Width/4,0),
|
||||
new Point(this.Width-this.Width/4,this.Height-40),
|
||||
new Point(this.Width,this.Height-40),
|
||||
new Point(this.Width/2,this.Height-1),
|
||||
new Point(0,this.Height-40),
|
||||
new Point(this.Width/4,this.Height-40),
|
||||
new Point(this.Width/4,0),
|
||||
new Point(this.Width-this.Width/4,0),
|
||||
};
|
||||
break;
|
||||
case ArrowDirection.Left_Right:
|
||||
ps = new Point[]
|
||||
{
|
||||
new Point(0,this.Height/2),
|
||||
new Point(40,0),
|
||||
new Point(40,this.Height/4),
|
||||
new Point(this.Width-40,this.Height/4),
|
||||
new Point(this.Width-40,0),
|
||||
new Point(this.Width-1,this.Height/2),
|
||||
new Point(this.Width-40,this.Height),
|
||||
new Point(this.Width-40,this.Height-this.Height/4),
|
||||
new Point(40,this.Height-this.Height/4),
|
||||
new Point(40,this.Height),
|
||||
new Point(0,this.Height/2),
|
||||
};
|
||||
break;
|
||||
case ArrowDirection.Top_Bottom:
|
||||
ps = new Point[]
|
||||
{
|
||||
new Point(this.Width/2,0),
|
||||
new Point(this.Width,40),
|
||||
new Point(this.Width-this.Width/4,40),
|
||||
new Point(this.Width-this.Width/4,this.Height-40),
|
||||
new Point(this.Width,this.Height-40),
|
||||
new Point(this.Width/2,this.Height-1),
|
||||
new Point(0,this.Height-40),
|
||||
new Point(this.Width/4,this.Height-40),
|
||||
new Point(this.Width/4,40),
|
||||
new Point(0,40),
|
||||
new Point(this.Width/2,0),
|
||||
};
|
||||
break;
|
||||
}
|
||||
m_path = new GraphicsPath();
|
||||
m_path.AddLines(ps);
|
||||
m_path.CloseAllFigures();
|
||||
}
|
||||
|
||||
/// <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;
|
||||
g.SetGDIHigh();
|
||||
base.Region = new Region(m_path);
|
||||
|
||||
g.FillPath(new SolidBrush(arrowColor), m_path);
|
||||
|
||||
if (borderColor != null && borderColor != Color.Empty)
|
||||
g.DrawPath(new Pen(new SolidBrush(borderColor.Value)), m_path);
|
||||
if (!string.IsNullOrEmpty(text))
|
||||
{
|
||||
var size = g.MeasureString(Text, Font);
|
||||
g.DrawString(Text, Font, new SolidBrush(ForeColor), new PointF((this.Width - size.Width) / 2, (this.Height - size.Height) / 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enum ArrowDirection
|
||||
/// </summary>
|
||||
public enum ArrowDirection
|
||||
{
|
||||
/// <summary>
|
||||
/// The left
|
||||
/// </summary>
|
||||
Left,
|
||||
/// <summary>
|
||||
/// The right
|
||||
/// </summary>
|
||||
Right,
|
||||
/// <summary>
|
||||
/// The top
|
||||
/// </summary>
|
||||
Top,
|
||||
/// <summary>
|
||||
/// The bottom
|
||||
/// </summary>
|
||||
Bottom,
|
||||
/// <summary>
|
||||
/// The left right
|
||||
/// </summary>
|
||||
Left_Right,
|
||||
/// <summary>
|
||||
/// The top bottom
|
||||
/// </summary>
|
||||
Top_Bottom
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,298 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : HZH_Controls
|
||||
// Created : 2019-09-09
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="UCBlower.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 System.ComponentModel;
|
||||
|
||||
namespace HZH_Controls.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UCBlower.
|
||||
/// Implements the <see cref="System.Windows.Forms.UserControl" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Windows.Forms.UserControl" />
|
||||
public class UCBlower : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// The entrance direction
|
||||
/// </summary>
|
||||
private BlowerEntranceDirection entranceDirection = BlowerEntranceDirection.None;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the entrance direction.
|
||||
/// </summary>
|
||||
/// <value>The entrance direction.</value>
|
||||
[Description("入口方向"), Category("自定义")]
|
||||
public BlowerEntranceDirection EntranceDirection
|
||||
{
|
||||
get { return entranceDirection; }
|
||||
set
|
||||
{
|
||||
entranceDirection = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The exit direction
|
||||
/// </summary>
|
||||
private BlowerExitDirection exitDirection = BlowerExitDirection.Right;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the exit direction.
|
||||
/// </summary>
|
||||
/// <value>The exit direction.</value>
|
||||
[Description("出口方向"), Category("自定义")]
|
||||
public BlowerExitDirection ExitDirection
|
||||
{
|
||||
get { return exitDirection; }
|
||||
set
|
||||
{
|
||||
exitDirection = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The blower color
|
||||
/// </summary>
|
||||
private Color blowerColor = Color.FromArgb(255, 77, 59);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the blower.
|
||||
/// </summary>
|
||||
/// <value>The color of the blower.</value>
|
||||
[Description("风机颜色"), Category("自定义")]
|
||||
public Color BlowerColor
|
||||
{
|
||||
get { return blowerColor; }
|
||||
set
|
||||
{
|
||||
blowerColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The fan color
|
||||
/// </summary>
|
||||
private Color fanColor = Color.FromArgb(3, 169, 243);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the fan.
|
||||
/// </summary>
|
||||
/// <value>The color of the fan.</value>
|
||||
[Description("风叶颜色"), Category("自定义")]
|
||||
public Color FanColor
|
||||
{
|
||||
get { return fanColor; }
|
||||
set
|
||||
{
|
||||
fanColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The m rect working
|
||||
/// </summary>
|
||||
Rectangle m_rectWorking;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UCBlower" /> class.
|
||||
/// </summary>
|
||||
public UCBlower()
|
||||
{
|
||||
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||
this.SetStyle(ControlStyles.DoubleBuffer, true);
|
||||
this.SetStyle(ControlStyles.ResizeRedraw, true);
|
||||
this.SetStyle(ControlStyles.Selectable, true);
|
||||
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
|
||||
this.SetStyle(ControlStyles.UserPaint, true);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.SizeChanged += UCBlower_SizeChanged;
|
||||
this.Size = new Size(120, 120);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the SizeChanged event of the UCBlower 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 UCBlower_SizeChanged(object sender, EventArgs e)
|
||||
{
|
||||
int intMin = Math.Min(this.Width, this.Height);
|
||||
m_rectWorking = new Rectangle((this.Width - (intMin / 3 * 2)) / 2, (this.Height - (intMin / 3 * 2)) / 2, (intMin / 3 * 2), (intMin / 3 * 2));
|
||||
}
|
||||
|
||||
/// <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;
|
||||
g.SetGDIHigh();
|
||||
GraphicsPath pathLineIn = new GraphicsPath();
|
||||
GraphicsPath pathLineOut = new GraphicsPath();
|
||||
int intLinePenWidth = 0;
|
||||
|
||||
switch (exitDirection)
|
||||
{
|
||||
case BlowerExitDirection.Left:
|
||||
g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(0, m_rectWorking.Top, this.Width / 2, m_rectWorking.Height / 2 - 5));
|
||||
intLinePenWidth = m_rectWorking.Height / 2 - 5;
|
||||
pathLineOut.AddLine(new Point(-10, m_rectWorking.Top + (m_rectWorking.Height / 2 - 5) / 2), new Point(m_rectWorking.Left + m_rectWorking.Width / 2, m_rectWorking.Top + (m_rectWorking.Height / 2 - 5) / 2));
|
||||
g.DrawLine(new Pen(new SolidBrush(blowerColor), 3), new Point(1, m_rectWorking.Top - 2), new Point(1, m_rectWorking.Top + (m_rectWorking.Height / 2 - 5) + 2));
|
||||
break;
|
||||
case BlowerExitDirection.Right:
|
||||
g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(this.Width / 2, m_rectWorking.Top, this.Width / 2, m_rectWorking.Height / 2 - 5));
|
||||
intLinePenWidth = m_rectWorking.Height / 2 - 5;
|
||||
pathLineOut.AddLine(new Point(this.Width + 10, m_rectWorking.Top + (m_rectWorking.Height / 2 - 5) / 2), new Point(m_rectWorking.Left + m_rectWorking.Width / 2, m_rectWorking.Top + (m_rectWorking.Height / 2 - 5) / 2));
|
||||
g.DrawLine(new Pen(new SolidBrush(blowerColor), 3), new Point(this.Width - 2, m_rectWorking.Top - 2), new Point(this.Width - 2, m_rectWorking.Top + (m_rectWorking.Height / 2 - 5) + 2));
|
||||
break;
|
||||
case BlowerExitDirection.Up:
|
||||
g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(m_rectWorking.Right - (m_rectWorking.Width / 2 - 5), 0, m_rectWorking.Width / 2 - 5, this.Height / 2));
|
||||
intLinePenWidth = m_rectWorking.Width / 2 - 5;
|
||||
pathLineOut.AddLine(new Point(m_rectWorking.Right - (m_rectWorking.Width / 2 - 5) / 2, -10), new Point(m_rectWorking.Right - (m_rectWorking.Width / 2 - 5) / 2, m_rectWorking.Top + m_rectWorking.Height / 2));
|
||||
g.DrawLine(new Pen(new SolidBrush(blowerColor), 3), new Point(m_rectWorking.Right + 2, 1), new Point(m_rectWorking.Right - (m_rectWorking.Width / 2 - 5) - 2, 1));
|
||||
break;
|
||||
}
|
||||
|
||||
switch (entranceDirection)
|
||||
{
|
||||
case BlowerEntranceDirection.Left:
|
||||
g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(0, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5, this.Width / 2, m_rectWorking.Height / 2 - 5));
|
||||
pathLineIn.AddLine(new Point(-10, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5 + (m_rectWorking.Height / 2 - 5) / 2), new Point(m_rectWorking.Left + m_rectWorking.Width / 2, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5 + (m_rectWorking.Height / 2 - 5) / 2));
|
||||
g.DrawLine(new Pen(new SolidBrush(blowerColor), 3), new Point(1, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5 - 2), new Point(1, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5 + (m_rectWorking.Height / 2 - 5) + 2));
|
||||
break;
|
||||
case BlowerEntranceDirection.Right:
|
||||
g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(this.Width / 2, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5, this.Width / 2, m_rectWorking.Height / 2 - 5));
|
||||
pathLineIn.AddLine(new Point(this.Width + 10, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5 + (m_rectWorking.Height / 2 - 5) / 2), new Point(m_rectWorking.Left + m_rectWorking.Width / 2, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5 + (m_rectWorking.Height / 2 - 5) / 2));
|
||||
g.DrawLine(new Pen(new SolidBrush(blowerColor), 3), new Point(this.Width - 2, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5 - 2), new Point(this.Width - 2, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5 + (m_rectWorking.Height / 2 - 5) + 2));
|
||||
break;
|
||||
case BlowerEntranceDirection.Up:
|
||||
g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(m_rectWorking.Left, 0, m_rectWorking.Width / 2 - 5, this.Height / 2));
|
||||
pathLineIn.AddLine(new Point(m_rectWorking.Left + (m_rectWorking.Width / 2 - 5) / 2, -10), new Point(m_rectWorking.Left + (m_rectWorking.Width / 2 - 5) / 2, m_rectWorking.Top + m_rectWorking.Height / 2));
|
||||
g.DrawLine(new Pen(new SolidBrush(blowerColor), 3), new Point(m_rectWorking.Left - 2, 1), new Point(m_rectWorking.Left + (m_rectWorking.Width / 2 - 5) + 2, 1));
|
||||
break;
|
||||
}
|
||||
|
||||
//渐变色
|
||||
int _intPenWidth = intLinePenWidth;
|
||||
int intCount = _intPenWidth / 2 / 4;
|
||||
for (int i = 0; i < intCount; i++)
|
||||
{
|
||||
int _penWidth = _intPenWidth / 2 - 4 * i;
|
||||
if (_penWidth <= 0)
|
||||
_penWidth = 1;
|
||||
if (entranceDirection != BlowerEntranceDirection.None)
|
||||
g.DrawPath(new Pen(new SolidBrush(Color.FromArgb(40, Color.White.R, Color.White.G, Color.White.B)), _penWidth), pathLineIn);
|
||||
g.DrawPath(new Pen(new SolidBrush(Color.FromArgb(40, Color.White.R, Color.White.G, Color.White.B)), _penWidth), pathLineOut);
|
||||
if (_penWidth == 1)
|
||||
break;
|
||||
}
|
||||
|
||||
//底座
|
||||
GraphicsPath gpDZ = new GraphicsPath();
|
||||
gpDZ.AddLines(new Point[]
|
||||
{
|
||||
new Point( m_rectWorking.Left+m_rectWorking.Width/2,m_rectWorking.Top+m_rectWorking.Height/2),
|
||||
new Point(m_rectWorking.Left+2,this.Height),
|
||||
new Point(m_rectWorking.Right-2,this.Height)
|
||||
});
|
||||
gpDZ.CloseAllFigures();
|
||||
g.FillPath(new SolidBrush(blowerColor), gpDZ);
|
||||
g.FillPath(new SolidBrush(Color.FromArgb(50, Color.White)), gpDZ);
|
||||
g.DrawLine(new Pen(new SolidBrush(blowerColor), 3), new Point(m_rectWorking.Left, this.Height - 2), new Point(m_rectWorking.Right, this.Height - 2));
|
||||
|
||||
//中心
|
||||
g.FillEllipse(new SolidBrush(blowerColor), m_rectWorking);
|
||||
g.FillEllipse(new SolidBrush(Color.FromArgb(20, Color.White)), m_rectWorking);
|
||||
|
||||
|
||||
//扇叶
|
||||
Rectangle _rect = new Rectangle(m_rectWorking.Left + (m_rectWorking.Width - (m_rectWorking.Width / 3 * 2)) / 2, m_rectWorking.Top + (m_rectWorking.Height - (m_rectWorking.Width / 3 * 2)) / 2, (m_rectWorking.Width / 3 * 2), (m_rectWorking.Width / 3 * 2));
|
||||
|
||||
int _splitCount = 8;
|
||||
float fltSplitValue = 360F / (float)_splitCount;
|
||||
for (int i = 0; i <= _splitCount; i++)
|
||||
{
|
||||
float fltAngle = (fltSplitValue * i - 180) % 360;
|
||||
float fltY1 = (float)(_rect.Top + _rect.Width / 2 - ((_rect.Width / 2) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
|
||||
float fltX1 = (float)(_rect.Left + (_rect.Width / 2 - ((_rect.Width / 2) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
|
||||
float fltY2 = 0;
|
||||
float fltX2 = 0;
|
||||
|
||||
fltY2 = (float)(_rect.Top + _rect.Width / 2 - ((_rect.Width / 4) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
|
||||
fltX2 = (float)(_rect.Left + (_rect.Width / 2 - ((_rect.Width / 4) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
|
||||
|
||||
g.DrawLine(new Pen(new SolidBrush(fanColor), 2), new PointF(fltX1, fltY1), new PointF(fltX2, fltY2));
|
||||
}
|
||||
|
||||
g.FillEllipse(new SolidBrush(fanColor), new Rectangle(_rect.Left + _rect.Width / 2 - _rect.Width / 4 + 2, _rect.Top + _rect.Width / 2 - _rect.Width / 4 + 2, _rect.Width / 2 - 4, _rect.Width / 2 - 4));
|
||||
g.FillEllipse(new SolidBrush(Color.FromArgb(50, Color.White)), new Rectangle(_rect.Left - 5, _rect.Top - 5, _rect.Width + 10, _rect.Height + 10));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Enum BlowerEntranceDirection
|
||||
/// </summary>
|
||||
public enum BlowerEntranceDirection
|
||||
{
|
||||
/// <summary>
|
||||
/// The none
|
||||
/// </summary>
|
||||
None,
|
||||
/// <summary>
|
||||
/// The left
|
||||
/// </summary>
|
||||
Left,
|
||||
/// <summary>
|
||||
/// The right
|
||||
/// </summary>
|
||||
Right,
|
||||
/// <summary>
|
||||
/// Up
|
||||
/// </summary>
|
||||
Up
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enum BlowerExitDirection
|
||||
/// </summary>
|
||||
public enum BlowerExitDirection
|
||||
{
|
||||
/// <summary>
|
||||
/// The left
|
||||
/// </summary>
|
||||
Left,
|
||||
/// <summary>
|
||||
/// The right
|
||||
/// </summary>
|
||||
Right,
|
||||
/// <summary>
|
||||
/// Up
|
||||
/// </summary>
|
||||
Up
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,368 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : HZH_Controls
|
||||
// Created : 2019-09-05
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="UCBottle.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 System.ComponentModel;
|
||||
|
||||
namespace HZH_Controls.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UCBottle.
|
||||
/// Implements the <see cref="System.Windows.Forms.UserControl" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Windows.Forms.UserControl" />
|
||||
public class UCBottle : UserControl
|
||||
{
|
||||
//瓶身区域
|
||||
/// <summary>
|
||||
/// The m working rect
|
||||
/// </summary>
|
||||
Rectangle m_workingRect;
|
||||
|
||||
/// <summary>
|
||||
/// The title
|
||||
/// </summary>
|
||||
string title = "瓶子1";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title.
|
||||
/// </summary>
|
||||
/// <value>The title.</value>
|
||||
[Description("标题"), Category("自定义")]
|
||||
public string Title
|
||||
{
|
||||
get { return title; }
|
||||
set
|
||||
{
|
||||
title = value;
|
||||
ResetWorkingRect();
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The bottle color
|
||||
/// </summary>
|
||||
private Color bottleColor = Color.FromArgb(255, 77, 59);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the bottle.
|
||||
/// </summary>
|
||||
/// <value>The color of the bottle.</value>
|
||||
[Description("瓶子颜色"), Category("自定义")]
|
||||
public Color BottleColor
|
||||
{
|
||||
get { return bottleColor; }
|
||||
set
|
||||
{
|
||||
bottleColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The bottle mouth color
|
||||
/// </summary>
|
||||
private Color bottleMouthColor = Color.FromArgb(105, 105, 105);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the bottle mouth.
|
||||
/// </summary>
|
||||
/// <value>The color of the bottle mouth.</value>
|
||||
[Description("瓶口颜色"), Category("自定义")]
|
||||
public Color BottleMouthColor
|
||||
{
|
||||
get { return bottleMouthColor; }
|
||||
set { bottleMouthColor = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The liquid color
|
||||
/// </summary>
|
||||
private Color liquidColor = Color.FromArgb(3, 169, 243);
|
||||
|
||||
/// <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;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置控件显示的文字的字体。
|
||||
/// </summary>
|
||||
/// <value>The font.</value>
|
||||
/// <PermissionSet>
|
||||
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||||
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
||||
/// <IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||||
/// </PermissionSet>
|
||||
[Description("文字字体"), Category("自定义")]
|
||||
public override Font Font
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Font;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.Font = value;
|
||||
ResetWorkingRect();
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置控件的前景色。
|
||||
/// </summary>
|
||||
/// <value>The color of the fore.</value>
|
||||
/// <PermissionSet>
|
||||
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||||
/// </PermissionSet>
|
||||
[Description("文字颜色"), Category("自定义")]
|
||||
public override System.Drawing.Color ForeColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.ForeColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.ForeColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The maximum value
|
||||
/// </summary>
|
||||
private decimal maxValue = 100;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum value.
|
||||
/// </summary>
|
||||
/// <value>The maximum value.</value>
|
||||
[Description("最大值"), Category("自定义")]
|
||||
public decimal MaxValue
|
||||
{
|
||||
get { return maxValue; }
|
||||
set
|
||||
{
|
||||
if (value < m_value)
|
||||
return;
|
||||
maxValue = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The m value
|
||||
/// </summary>
|
||||
private decimal m_value = 50;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value.
|
||||
/// </summary>
|
||||
/// <value>The value.</value>
|
||||
[Description("值"), Category("自定义")]
|
||||
public decimal Value
|
||||
{
|
||||
get { return m_value; }
|
||||
set
|
||||
{
|
||||
if (value <= 0 || value > maxValue)
|
||||
return;
|
||||
m_value = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The m no
|
||||
/// </summary>
|
||||
private string m_NO;
|
||||
/// <summary>
|
||||
/// Gets or sets the NO.
|
||||
/// </summary>
|
||||
/// <value>The no.</value>
|
||||
[Description("编号"), Category("自定义")]
|
||||
public string NO
|
||||
{
|
||||
get { return m_NO; }
|
||||
set
|
||||
{
|
||||
m_NO = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UCBottle" /> class.
|
||||
/// </summary>
|
||||
public UCBottle()
|
||||
{
|
||||
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||
this.SetStyle(ControlStyles.DoubleBuffer, true);
|
||||
this.SetStyle(ControlStyles.ResizeRedraw, true);
|
||||
this.SetStyle(ControlStyles.Selectable, true);
|
||||
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
|
||||
this.SetStyle(ControlStyles.UserPaint, true);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.SizeChanged += UCBottle_SizeChanged;
|
||||
this.Size = new Size(100, 150);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the SizeChanged event of the UCBottle 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 UCBottle_SizeChanged(object sender, EventArgs e)
|
||||
{
|
||||
ResetWorkingRect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the working rect.
|
||||
/// </summary>
|
||||
private void ResetWorkingRect()
|
||||
{
|
||||
var g = this.CreateGraphics();
|
||||
var size = g.MeasureString(title, Font);
|
||||
m_workingRect = new Rectangle(0, (int)size.Height + 10, this.Width, this.Height - ((int)size.Height + 10) - 15);
|
||||
}
|
||||
|
||||
/// <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;
|
||||
g.SetGDIHigh();
|
||||
//写文字
|
||||
var size = g.MeasureString(title, Font);
|
||||
g.DrawString(title, Font, new SolidBrush(ForeColor), new PointF((this.Width - size.Width) / 2, 2));
|
||||
|
||||
//画空瓶子
|
||||
GraphicsPath pathPS = new GraphicsPath();
|
||||
Point[] psPS = new Point[]
|
||||
{
|
||||
new Point(m_workingRect.Left, m_workingRect.Top),
|
||||
new Point(m_workingRect.Right - 1, m_workingRect.Top),
|
||||
new Point(m_workingRect.Right - 1, m_workingRect.Bottom - 15),
|
||||
new Point(m_workingRect.Right - 1 - m_workingRect.Width / 4, m_workingRect.Bottom),
|
||||
new Point(m_workingRect.Left + m_workingRect.Width / 4, m_workingRect.Bottom),
|
||||
new Point(m_workingRect.Left, m_workingRect.Bottom - 15),
|
||||
};
|
||||
pathPS.AddLines(psPS);
|
||||
pathPS.CloseAllFigures();
|
||||
g.FillPath(new SolidBrush(bottleColor), pathPS);
|
||||
//画液体
|
||||
decimal decYTHeight = (m_value / maxValue) * m_workingRect.Height;
|
||||
GraphicsPath pathYT = new GraphicsPath();
|
||||
Rectangle rectYT = Rectangle.Empty;
|
||||
if (decYTHeight < 15)
|
||||
{
|
||||
PointF[] psYT = new PointF[]
|
||||
{
|
||||
new PointF((float)(m_workingRect.Left+(15-decYTHeight))+3,(float)(m_workingRect.Bottom-decYTHeight)),
|
||||
new PointF((float)(m_workingRect.Right-(15-decYTHeight))-3,(float)(m_workingRect.Bottom-decYTHeight)),
|
||||
new PointF(m_workingRect.Right-1-m_workingRect.Width/4, m_workingRect.Bottom),
|
||||
new PointF(m_workingRect.Left+m_workingRect.Width/4, m_workingRect.Bottom),
|
||||
};
|
||||
pathYT.AddLines(psYT);
|
||||
pathYT.CloseAllFigures();
|
||||
rectYT = new Rectangle((m_workingRect.Left + (15 - (int)decYTHeight)) + 3, m_workingRect.Bottom - (int)decYTHeight - 5, m_workingRect.Width - (int)(15 - decYTHeight) * 2 - 8, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
PointF[] psYT = new PointF[]
|
||||
{
|
||||
new PointF(m_workingRect.Left,(float)(m_workingRect.Bottom-decYTHeight)),
|
||||
new PointF(m_workingRect.Right-1,(float)(m_workingRect.Bottom-decYTHeight)),
|
||||
new PointF(m_workingRect.Right-1,m_workingRect.Bottom-15),
|
||||
new PointF(m_workingRect.Right-1-m_workingRect.Width/4, m_workingRect.Bottom),
|
||||
new PointF(m_workingRect.Left+m_workingRect.Width/4, m_workingRect.Bottom),
|
||||
new PointF(m_workingRect.Left,m_workingRect.Bottom-15),
|
||||
};
|
||||
pathYT.AddLines(psYT);
|
||||
pathYT.CloseAllFigures();
|
||||
rectYT = new Rectangle(m_workingRect.Left, m_workingRect.Bottom - (int)decYTHeight - 5, m_workingRect.Width, 10);
|
||||
}
|
||||
|
||||
g.FillPath(new SolidBrush(liquidColor), pathYT);
|
||||
g.FillPath(new SolidBrush(Color.FromArgb(50, bottleMouthColor)), pathYT);
|
||||
//画液体面
|
||||
g.FillEllipse(new SolidBrush(liquidColor), rectYT);
|
||||
g.FillEllipse(new SolidBrush(Color.FromArgb(50, Color.White)), rectYT);
|
||||
|
||||
//画高亮
|
||||
int intCount = m_workingRect.Width / 2 / 4;
|
||||
int intSplit = (255 - 100) / intCount;
|
||||
for (int i = 0; i < intCount; i++)
|
||||
{
|
||||
int _penWidth = m_workingRect.Width / 2 - 4 * i;
|
||||
if (_penWidth <= 0)
|
||||
_penWidth = 1;
|
||||
g.DrawLine(new Pen(new SolidBrush(Color.FromArgb(10, Color.White)), _penWidth), new Point(m_workingRect.Width / 2, m_workingRect.Top), new Point(m_workingRect.Width / 2, m_workingRect.Bottom - 15));
|
||||
if (_penWidth == 1)
|
||||
break;
|
||||
}
|
||||
|
||||
//画瓶底
|
||||
g.FillEllipse(new SolidBrush(bottleColor), new RectangleF(m_workingRect.Left, m_workingRect.Top - 5, m_workingRect.Width - 2, 10));
|
||||
g.FillEllipse(new SolidBrush(Color.FromArgb(50, Color.White)), new RectangleF(m_workingRect.Left, m_workingRect.Top - 5, m_workingRect.Width - 2, 10));
|
||||
//画瓶口
|
||||
g.FillRectangle(new SolidBrush(bottleMouthColor), new Rectangle(m_workingRect.Left + m_workingRect.Width / 4, m_workingRect.Bottom, m_workingRect.Width / 2, 15));
|
||||
//画瓶颈阴影
|
||||
GraphicsPath pathPJ = new GraphicsPath();
|
||||
Point[] psPJ = new Point[]
|
||||
{
|
||||
new Point(m_workingRect.Left, m_workingRect.Bottom-15),
|
||||
new Point(m_workingRect.Right-1, m_workingRect.Bottom-15),
|
||||
new Point(m_workingRect.Right-1-m_workingRect.Width/4, m_workingRect.Bottom),
|
||||
new Point(m_workingRect.Left+m_workingRect.Width/4, m_workingRect.Bottom)
|
||||
};
|
||||
pathPJ.AddLines(psPJ);
|
||||
pathPJ.CloseAllFigures();
|
||||
g.FillPath(new SolidBrush(Color.FromArgb(50, bottleMouthColor)), pathPJ);
|
||||
|
||||
//写编号
|
||||
if (!string.IsNullOrEmpty(m_NO))
|
||||
{
|
||||
var nosize = g.MeasureString(m_NO, Font);
|
||||
g.DrawString(m_NO, Font, new SolidBrush(ForeColor), new PointF((this.Width - nosize.Width) / 2, m_workingRect.Top + 10));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,803 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : HZH_Controls
|
||||
// Created : 2019-09-04
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="UCConduit.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 System.ComponentModel;
|
||||
|
||||
namespace HZH_Controls.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UCConduit.
|
||||
/// Implements the <see cref="System.Windows.Forms.UserControl" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Windows.Forms.UserControl" />
|
||||
public class UCConduit : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// The conduit style
|
||||
/// </summary>
|
||||
private ConduitStyle conduitStyle = ConduitStyle.Horizontal_None_None;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the conduit style.
|
||||
/// </summary>
|
||||
/// <value>The conduit style.</value>
|
||||
[Description("样式"), Category("自定义")]
|
||||
public ConduitStyle ConduitStyle
|
||||
{
|
||||
get { return conduitStyle; }
|
||||
set
|
||||
{
|
||||
string strOld = conduitStyle.ToString().Substring(0, 1);
|
||||
string strNew = value.ToString().Substring(0, 1);
|
||||
conduitStyle = value;
|
||||
if (strOld != strNew)
|
||||
{
|
||||
this.Size = new Size(this.Size.Height, this.Size.Width);
|
||||
}
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The conduit color
|
||||
/// </summary>
|
||||
private Color conduitColor = Color.FromArgb(255, 77, 59);
|
||||
[Description("颜色"), Category("自定义")]
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the conduit.
|
||||
/// </summary>
|
||||
/// <value>The color of the conduit.</value>
|
||||
public Color ConduitColor
|
||||
{
|
||||
get { return conduitColor; }
|
||||
set
|
||||
{
|
||||
conduitColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The liquid color
|
||||
/// </summary>
|
||||
private Color liquidColor = Color.FromArgb(3, 169, 243);
|
||||
|
||||
/// <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 != LiquidDirection.None)
|
||||
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 == LiquidDirection.None)
|
||||
m_timer.Enabled = false;
|
||||
else
|
||||
m_timer.Enabled = true;
|
||||
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The liquid speed
|
||||
/// </summary>
|
||||
private int liquidSpeed = 100;
|
||||
|
||||
/// <summary>
|
||||
/// 液体流速,越小,速度越快Gets or sets the liquid speed.
|
||||
/// </summary>
|
||||
/// <value>The liquid speed.</value>
|
||||
[Description("液体流速,越小,速度越快"), Category("自定义")]
|
||||
public int LiquidSpeed
|
||||
{
|
||||
get { return liquidSpeed; }
|
||||
set
|
||||
{
|
||||
if (value <= 0)
|
||||
return;
|
||||
liquidSpeed = value;
|
||||
m_timer.Interval = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The conduit width
|
||||
/// </summary>
|
||||
int conduitWidth = 50;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the width of the conduit.
|
||||
/// </summary>
|
||||
/// <value>The width of the conduit.</value>
|
||||
[Description("管道宽度,当ConduitStyle的值是Horizontal_Tilt_Up,Horizontal_Tilt_Down,Vertical_Tilt_Left,Vertical_Tilt_Right时有效,其他时候将根据管道大小使用自动宽度"), Category("自定义")]
|
||||
public int ConduitWidth
|
||||
{
|
||||
get { return conduitWidth; }
|
||||
set
|
||||
{
|
||||
conduitWidth = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The int pen width
|
||||
/// </summary>
|
||||
int intPenWidth = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The int line left
|
||||
/// </summary>
|
||||
int intLineLeft = 0;
|
||||
/// <summary>
|
||||
/// The m timer
|
||||
/// </summary>
|
||||
Timer m_timer;
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UCConduit" /> class.
|
||||
/// </summary>
|
||||
public UCConduit()
|
||||
{
|
||||
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||
this.SetStyle(ControlStyles.DoubleBuffer, true);
|
||||
this.SetStyle(ControlStyles.ResizeRedraw, true);
|
||||
this.SetStyle(ControlStyles.Selectable, true);
|
||||
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
|
||||
this.SetStyle(ControlStyles.UserPaint, true);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.SizeChanged += UCConduit_SizeChanged;
|
||||
this.Size = new Size(200, 50);
|
||||
m_timer = new Timer();
|
||||
m_timer.Interval = 100;
|
||||
m_timer.Tick += timer_Tick;
|
||||
m_timer.Enabled = true;
|
||||
}
|
||||
|
||||
/// <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 += 2;
|
||||
if (intLineLeft > 12)
|
||||
intLineLeft = 0;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Handles the SizeChanged event of the UCConduit 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 UCConduit_SizeChanged(object sender, EventArgs e)
|
||||
{
|
||||
intPenWidth = conduitStyle.ToString().StartsWith("H") ? this.Height : this.Width;
|
||||
}
|
||||
|
||||
/// <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);
|
||||
Graphics g = e.Graphics;
|
||||
|
||||
List<ArcEntity> lstArcs = new List<ArcEntity>();
|
||||
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
GraphicsPath linePath = new GraphicsPath();
|
||||
List<Point[]> tileLine = new List<Point[]>();
|
||||
switch (conduitStyle)
|
||||
{
|
||||
#region H English:H
|
||||
case ConduitStyle.Horizontal_None_None:
|
||||
path.AddLines(new PointF[]
|
||||
{
|
||||
new PointF(0, 0),
|
||||
new PointF(this.ClientRectangle.Right, 0),
|
||||
new PointF(this.ClientRectangle.Right, this.Height),
|
||||
new PointF(0, this.Height)
|
||||
});
|
||||
path.CloseAllFigures();
|
||||
linePath.AddLine(0, this.Height / 2, this.Width, this.Height / 2);
|
||||
break;
|
||||
case ConduitStyle.Horizontal_Up_None:
|
||||
path.AddLines(new PointF[]
|
||||
{
|
||||
new PointF(0, 0),
|
||||
new PointF(this.ClientRectangle.Right, 0),
|
||||
new PointF(this.ClientRectangle.Right, this.Height),
|
||||
new PointF(0+intPenWidth, this.Height)
|
||||
});
|
||||
path.AddArc(new Rectangle(0, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), 90, 90);
|
||||
path.CloseAllFigures();
|
||||
|
||||
linePath.AddArc(new Rectangle(intPenWidth / 2 + 1, -1 * intPenWidth / 2 - 1, intPenWidth, intPenWidth), 181, -91);
|
||||
linePath.AddLine(intPenWidth, this.Height / 2, this.Width, this.Height / 2);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(0, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), startAngle = 90, sweepAngle = 90 });
|
||||
break;
|
||||
case ConduitStyle.Horizontal_Down_None:
|
||||
path.AddLines(new PointF[]
|
||||
{
|
||||
new PointF(intPenWidth, 0),
|
||||
new PointF(this.ClientRectangle.Right, 0),
|
||||
new PointF(this.ClientRectangle.Right, this.Height),
|
||||
new PointF(0, this.Height)
|
||||
});
|
||||
path.AddArc(new Rectangle(0, -1, intPenWidth * 2, intPenWidth * 2), 180, 90);
|
||||
path.CloseAllFigures();
|
||||
|
||||
linePath.AddArc(new Rectangle(intPenWidth / 2 + 1, this.Height / 2, intPenWidth, intPenWidth), 179, 91);
|
||||
linePath.AddLine(intPenWidth + 1, this.Height / 2, this.Width, this.Height / 2);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(0, -1, intPenWidth * 2, intPenWidth * 2), startAngle = 180, sweepAngle = 90 });
|
||||
break;
|
||||
case ConduitStyle.Horizontal_None_Up:
|
||||
path.AddLines(new PointF[]
|
||||
{
|
||||
new PointF(this.ClientRectangle.Right-intPenWidth, this.Height),
|
||||
new PointF(0, this.Height),
|
||||
new PointF(0, 0),
|
||||
new PointF(this.ClientRectangle.Right-intPenWidth, 0)
|
||||
});
|
||||
path.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), 0, 90);
|
||||
path.CloseAllFigures();
|
||||
|
||||
linePath.AddLine(0, this.Height / 2, this.Width - intPenWidth, this.Height / 2);
|
||||
linePath.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth - intPenWidth / 2 - 1, -1 * intPenWidth / 2 - 1, intPenWidth, intPenWidth), 91, -91);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), startAngle = 0, sweepAngle = 90 });
|
||||
break;
|
||||
case ConduitStyle.Horizontal_None_Down:
|
||||
path.AddLines(new PointF[]
|
||||
{
|
||||
new PointF(this.ClientRectangle.Right, this.Height),
|
||||
new PointF(0, this.Height),
|
||||
new PointF(0, 0),
|
||||
new PointF(this.ClientRectangle.Right-intPenWidth, 0)
|
||||
});
|
||||
path.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, -1, intPenWidth * 2, intPenWidth * 2), 270, 90);
|
||||
path.CloseAllFigures();
|
||||
|
||||
linePath.AddLine(0, this.Height / 2, this.Width - intPenWidth - 1, this.Height / 2);
|
||||
linePath.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth - intPenWidth / 2 - 1, intPenWidth / 2, intPenWidth, intPenWidth), 269, 91);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, -1, intPenWidth * 2, intPenWidth * 2), startAngle = 270, sweepAngle = 90 });
|
||||
break;
|
||||
case ConduitStyle.Horizontal_Down_Up:
|
||||
path.AddLine(new Point(intPenWidth, 0), new Point(this.Width, 0));
|
||||
path.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), 0, 90);
|
||||
path.AddLine(new Point(this.Width - intPenWidth, this.Height), new Point(0, this.Height));
|
||||
path.AddArc(new Rectangle(0, -1, intPenWidth * 2, intPenWidth * 2), 180, 90);
|
||||
path.CloseAllFigures();
|
||||
|
||||
linePath.AddArc(new Rectangle(intPenWidth / 2 + 1, this.Height / 2, intPenWidth, intPenWidth), 179, 91);
|
||||
//linePath.AddLine(intPenWidth, this.Height / 2, this.Width - intPenWidth, this.Height / 2);
|
||||
linePath.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth - intPenWidth / 2 - 1, -1 * intPenWidth / 2 - 1, intPenWidth, intPenWidth), 91, -91);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(0, -1, intPenWidth * 2, intPenWidth * 2), startAngle = 180, sweepAngle = 90 });
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), startAngle = 0, sweepAngle = 90 });
|
||||
break;
|
||||
case ConduitStyle.Horizontal_Up_Down:
|
||||
path.AddLine(new Point(0, 0), new Point(this.Width - intPenWidth, 0));
|
||||
path.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, -1, intPenWidth * 2, intPenWidth * 2), 270, 90);
|
||||
path.AddLine(new Point(this.Width, this.Height), new Point(intPenWidth, this.Height));
|
||||
path.AddArc(new Rectangle(0, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), 90, 90);
|
||||
path.CloseAllFigures();
|
||||
|
||||
linePath.AddArc(new Rectangle(intPenWidth / 2 + 1, -1 * intPenWidth / 2 - 1, intPenWidth, intPenWidth), 181, -91);
|
||||
linePath.AddLine(intPenWidth, this.Height / 2, this.Width - intPenWidth - 1, this.Height / 2);
|
||||
linePath.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth - intPenWidth / 2 - 1, intPenWidth / 2, intPenWidth, intPenWidth), 269, 91);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(0, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), startAngle = 90, sweepAngle = 90 });
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, -1, intPenWidth * 2, intPenWidth * 2), startAngle = 270, sweepAngle = 90 });
|
||||
break;
|
||||
case ConduitStyle.Horizontal_Up_Up:
|
||||
path.AddLine(new Point(0, 0), new Point(this.Width, 0));
|
||||
path.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), 0, 90);
|
||||
path.AddLine(new Point(this.Width - intPenWidth, this.Height), new Point(intPenWidth, this.Height));
|
||||
path.AddArc(new Rectangle(0, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), 90, 90);
|
||||
path.CloseAllFigures();
|
||||
|
||||
linePath.AddArc(new Rectangle(intPenWidth / 2 + 1, -1 * intPenWidth / 2 - 1, intPenWidth, intPenWidth), 181, -91);
|
||||
//linePath.AddLine(intPenWidth, this.Height / 2, this.Width - intPenWidth, this.Height / 2);
|
||||
linePath.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth - intPenWidth / 2 - 1, -1 * intPenWidth / 2 - 1, intPenWidth, intPenWidth), 91, -91);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(0, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), startAngle = 90, sweepAngle = 90 });
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), startAngle = 0, sweepAngle = 90 });
|
||||
break;
|
||||
case ConduitStyle.Horizontal_Down_Down:
|
||||
path.AddLine(new Point(intPenWidth, 0), new Point(this.Width - intPenWidth, 0));
|
||||
path.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, -1, intPenWidth * 2, intPenWidth * 2), 270, 90);
|
||||
path.AddLine(new Point(this.Width, this.Height), new Point(0, this.Height));
|
||||
path.AddArc(new Rectangle(0, -1, intPenWidth * 2, intPenWidth * 2), 180, 90);
|
||||
path.CloseAllFigures();
|
||||
|
||||
linePath.AddArc(new Rectangle(intPenWidth / 2 + 1, this.Height / 2, intPenWidth, intPenWidth), 179, 91);
|
||||
linePath.AddLine(intPenWidth + 1, this.Height / 2, this.Width - intPenWidth - 1, this.Height / 2);
|
||||
linePath.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth - intPenWidth / 2 - 1, intPenWidth / 2, intPenWidth, intPenWidth), 269, 91);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(0, -1, intPenWidth * 2, intPenWidth * 2), startAngle = 180, sweepAngle = 90 });
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, -1, intPenWidth * 2, intPenWidth * 2), startAngle = 270, sweepAngle = 90 });
|
||||
break;
|
||||
|
||||
case ConduitStyle.Horizontal_Tilt_Up:
|
||||
|
||||
double angleUp = Math.Atan((this.ClientRectangle.Height - conduitWidth) / (double)this.ClientRectangle.Width);
|
||||
angleUp = angleUp / Math.PI * 180f;
|
||||
path.AddArc(new Rectangle(this.ClientRectangle.Left - conduitWidth, this.ClientRectangle.Bottom - conduitWidth * 2, conduitWidth * 2, conduitWidth * 2), 90, -1 * (float)angleUp);
|
||||
path.AddLine(new Point(this.ClientRectangle.Right, this.ClientRectangle.Top + conduitWidth), new Point(this.ClientRectangle.Right, this.ClientRectangle.Top));
|
||||
path.AddArc(new Rectangle(this.ClientRectangle.Right - conduitWidth, this.ClientRectangle.Top, conduitWidth * 2, conduitWidth * 2), 270, -1 * (float)angleUp);
|
||||
path.AddLine(new Point(this.ClientRectangle.Left, this.ClientRectangle.Bottom - conduitWidth), new Point(this.ClientRectangle.Left, this.ClientRectangle.Bottom));
|
||||
path.CloseAllFigures();
|
||||
|
||||
|
||||
linePath.AddArc(new Rectangle(this.ClientRectangle.Right - conduitWidth / 2, this.ClientRectangle.Top + conduitWidth / 2, conduitWidth, conduitWidth), 270, -1 * (float)angleUp);
|
||||
linePath.AddArc(new Rectangle(this.ClientRectangle.Left - conduitWidth / 2, this.ClientRectangle.Bottom - 1 - conduitWidth - conduitWidth / 2, conduitWidth, conduitWidth), 95 - (float)angleUp, (float)angleUp + 5);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Left - conduitWidth, this.ClientRectangle.Bottom - conduitWidth * 2, conduitWidth * 2, conduitWidth * 2), startAngle = 90, sweepAngle = -1 * (float)angleUp });
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - conduitWidth, this.ClientRectangle.Top, conduitWidth * 2, conduitWidth * 2), startAngle = 270, sweepAngle = -1 * (float)angleUp });
|
||||
|
||||
tileLine.Add(new Point[]
|
||||
{
|
||||
new Point((int)(this.ClientRectangle.Right+1 - Math.Sin(Math.PI * (angleUp / 180.00F)) * conduitWidth),(int)( this.ClientRectangle.Top + conduitWidth - Math.Cos(Math.PI * (angleUp / 180.00F)) * conduitWidth)),
|
||||
new Point(this.ClientRectangle.Left,this.ClientRectangle.Bottom-conduitWidth-1)
|
||||
});
|
||||
tileLine.Add(new Point[]
|
||||
{
|
||||
new Point((int)(this.ClientRectangle.Left+1 + Math.Sin(Math.PI * (angleUp / 180.00F)) * conduitWidth),(int)( this.ClientRectangle.Bottom - conduitWidth + Math.Cos(Math.PI * (angleUp / 180.00F)) * conduitWidth)),
|
||||
new Point(this.ClientRectangle.Right,this.ClientRectangle.Top+conduitWidth)
|
||||
});
|
||||
|
||||
break;
|
||||
case ConduitStyle.Horizontal_Tilt_Down:
|
||||
double angleDown = Math.Atan((this.ClientRectangle.Height - conduitWidth) / (double)this.ClientRectangle.Width);
|
||||
angleDown = angleDown / Math.PI * 180f;
|
||||
path.AddArc(new Rectangle(this.ClientRectangle.Left - conduitWidth, this.ClientRectangle.Top, conduitWidth * 2, conduitWidth * 2), 270, (float)angleDown);
|
||||
path.AddLine(new Point(this.ClientRectangle.Right, this.ClientRectangle.Bottom - conduitWidth), new Point(this.ClientRectangle.Right, this.ClientRectangle.Bottom));
|
||||
path.AddArc(new Rectangle(this.ClientRectangle.Right - conduitWidth, this.ClientRectangle.Bottom - conduitWidth * 2, conduitWidth * 2, conduitWidth * 2), 90, (float)angleDown);
|
||||
path.AddLine(new Point(this.ClientRectangle.Left, this.ClientRectangle.Top + conduitWidth), new Point(this.ClientRectangle.Left, this.ClientRectangle.Top));
|
||||
path.CloseAllFigures();
|
||||
|
||||
|
||||
linePath.AddArc(new Rectangle(this.ClientRectangle.Left - conduitWidth / 2, this.ClientRectangle.Top + conduitWidth / 2, conduitWidth, conduitWidth), 265, (float)angleDown + 5);
|
||||
linePath.AddArc(new Rectangle(this.ClientRectangle.Right - conduitWidth / 2, this.ClientRectangle.Bottom - conduitWidth - conduitWidth / 2 - 1, conduitWidth, conduitWidth), 90 + (float)angleDown, -1 * (float)angleDown - 5);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Left - conduitWidth, this.ClientRectangle.Top, conduitWidth * 2, conduitWidth * 2), startAngle = 270, sweepAngle = (float)angleDown });
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - conduitWidth, this.ClientRectangle.Bottom - conduitWidth * 2, conduitWidth * 2, conduitWidth * 2), startAngle = 90, sweepAngle = (float)angleDown });
|
||||
|
||||
tileLine.Add(new Point[]
|
||||
{
|
||||
new Point((int)(this.ClientRectangle.Left + Math.Sin(Math.PI * (angleDown / 180.00F)) * conduitWidth),(int)( this.ClientRectangle.Top + conduitWidth - Math.Cos(Math.PI * (angleDown / 180.00F)) * conduitWidth)),
|
||||
new Point(this.ClientRectangle.Right-1,this.ClientRectangle.Bottom-conduitWidth-1)
|
||||
});
|
||||
tileLine.Add(new Point[]
|
||||
{
|
||||
new Point((int)(this.ClientRectangle.Right - Math.Sin(Math.PI * (angleDown / 180.00F)) * conduitWidth),(int)( this.ClientRectangle.Bottom - conduitWidth + Math.Cos(Math.PI * (angleDown / 180.00F)) * conduitWidth)),
|
||||
new Point(this.ClientRectangle.Left,this.ClientRectangle.Top+conduitWidth)
|
||||
});
|
||||
break;
|
||||
#endregion
|
||||
|
||||
#region V English:V
|
||||
case ConduitStyle.Vertical_None_None:
|
||||
path.AddLines(new PointF[]
|
||||
{
|
||||
new PointF(0, 0),
|
||||
new PointF(this.ClientRectangle.Right, 0),
|
||||
new PointF(this.ClientRectangle.Right, this.Height),
|
||||
new PointF(0, this.Height)
|
||||
});
|
||||
path.CloseAllFigures();
|
||||
linePath.AddLine(this.Width / 2, 0, this.Width / 2, this.Height);
|
||||
break;
|
||||
case ConduitStyle.Vertical_Left_None:
|
||||
path.AddLines(new PointF[]
|
||||
{
|
||||
new PointF(this.ClientRectangle.Right, intPenWidth),
|
||||
new PointF(this.ClientRectangle.Right, this.Height),
|
||||
new PointF(0, this.Height),
|
||||
new PointF(0, 0)
|
||||
});
|
||||
path.AddArc(new Rectangle(-1 * intPenWidth, 0, intPenWidth * 2, intPenWidth * 2), 270, 90);
|
||||
path.CloseAllFigures();
|
||||
|
||||
linePath.AddArc(new Rectangle(-1 * intPenWidth / 2 - 1, intPenWidth / 2 + 1, intPenWidth, intPenWidth), 269, 91);
|
||||
linePath.AddLine(intPenWidth / 2, intPenWidth, intPenWidth / 2, this.Height);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1 * intPenWidth, 0, intPenWidth * 2, intPenWidth * 2), startAngle = 270, sweepAngle = 90 });
|
||||
break;
|
||||
case ConduitStyle.Vertical_Right_None:
|
||||
path.AddLines(new PointF[]
|
||||
{
|
||||
new PointF(this.ClientRectangle.Right, 0),
|
||||
new PointF(this.ClientRectangle.Right, this.Height),
|
||||
new PointF(0, this.Height),
|
||||
new PointF(0, intPenWidth)
|
||||
});
|
||||
path.AddArc(new Rectangle(-1, 0, intPenWidth * 2, intPenWidth * 2), 180, 90);
|
||||
path.CloseAllFigures();
|
||||
|
||||
linePath.AddArc(new Rectangle(intPenWidth / 2, intPenWidth / 2 + 1, intPenWidth, intPenWidth), 271, -91);
|
||||
linePath.AddLine(intPenWidth / 2, intPenWidth + 1, intPenWidth / 2, this.Height);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1, 0, intPenWidth * 2, intPenWidth * 2), startAngle = 180, sweepAngle = 90 });
|
||||
break;
|
||||
case ConduitStyle.Vertical_None_Left:
|
||||
path.AddLines(new PointF[]
|
||||
{
|
||||
new PointF(0, this.Height),
|
||||
new PointF(0, 0),
|
||||
new PointF(this.ClientRectangle.Right, 0),
|
||||
new PointF(this.ClientRectangle.Right, this.Height-intPenWidth),
|
||||
});
|
||||
path.AddArc(new Rectangle(-1 * intPenWidth, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), 0, 90);
|
||||
path.CloseAllFigures();
|
||||
|
||||
linePath.AddLine(this.Width / 2, 0, this.Width / 2, this.Height - intPenWidth);
|
||||
linePath.AddArc(new Rectangle(-1 * intPenWidth / 2 - 1, this.Height - intPenWidth - intPenWidth / 2 - 1, intPenWidth, intPenWidth), -1, 91);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1 * intPenWidth, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), startAngle = 0, sweepAngle = 90 });
|
||||
break;
|
||||
case ConduitStyle.Vertical_None_Right:
|
||||
path.AddLines(new PointF[]
|
||||
{
|
||||
new PointF(0, this.Height-intPenWidth),
|
||||
new PointF(0, 0),
|
||||
new PointF(this.ClientRectangle.Right, 0),
|
||||
new PointF(this.ClientRectangle.Right, this.Height),
|
||||
});
|
||||
path.AddArc(new Rectangle(-1, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), 90, 90);
|
||||
path.CloseAllFigures();
|
||||
|
||||
linePath.AddLine(this.Width / 2, 0, this.Width / 2, this.Height - intPenWidth - 1);
|
||||
linePath.AddArc(new Rectangle(intPenWidth / 2, this.Height - intPenWidth - intPenWidth / 2 - 1, intPenWidth, intPenWidth), 181, -91);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), startAngle = 90, sweepAngle = 90 });
|
||||
break;
|
||||
case ConduitStyle.Vertical_Left_Right:
|
||||
path.AddLine(this.Width, intPenWidth, this.Width, this.Height);
|
||||
path.AddArc(new Rectangle(-1, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), 90, 90);
|
||||
path.AddLine(0, this.Height - intPenWidth, 0, 0);
|
||||
path.AddArc(new Rectangle(-1 * intPenWidth, 0, intPenWidth * 2, intPenWidth * 2), 270, 90);
|
||||
path.CloseAllFigures();
|
||||
|
||||
linePath.AddArc(new Rectangle(-1 * intPenWidth / 2 - 1, intPenWidth / 2 + 1, intPenWidth, intPenWidth), 269, 91);
|
||||
//linePath.AddLine(intPenWidth / 2, intPenWidth, intPenWidth / 2, this.Height - intPenWidth);
|
||||
linePath.AddArc(new Rectangle(intPenWidth / 2, this.Height - intPenWidth - intPenWidth / 2 - 1, intPenWidth, intPenWidth), 181, -91);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1 * intPenWidth, 0, intPenWidth * 2, intPenWidth * 2), startAngle = 270, sweepAngle = 90 });
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), startAngle = 90, sweepAngle = 90 });
|
||||
break;
|
||||
case ConduitStyle.Vertical_Right_Left:
|
||||
path.AddLine(this.Width, 0, this.Width, this.Height - intPenWidth);
|
||||
path.AddArc(new Rectangle(-1 * intPenWidth, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), 0, 90);
|
||||
path.AddLine(0, this.Height, 0, intPenWidth);
|
||||
path.AddArc(new Rectangle(-1, 0, intPenWidth * 2, intPenWidth * 2), 180, 90);
|
||||
path.CloseAllFigures();
|
||||
|
||||
linePath.AddArc(new Rectangle(intPenWidth / 2, intPenWidth / 2 + 1, intPenWidth, intPenWidth), 271, -91);
|
||||
//linePath.AddLine(intPenWidth / 2, intPenWidth, intPenWidth / 2, this.Height - intPenWidth);
|
||||
linePath.AddArc(new Rectangle(-1 * intPenWidth / 2 - 1, this.Height - intPenWidth - intPenWidth / 2 - 1, intPenWidth, intPenWidth), -1, 91);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1, 0, intPenWidth * 2, intPenWidth * 2), startAngle = 180, sweepAngle = 90 });
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1 * intPenWidth, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), startAngle = 0, sweepAngle = 90 });
|
||||
break;
|
||||
case ConduitStyle.Vertical_Left_Left:
|
||||
path.AddLine(this.Width, intPenWidth, this.Width, this.Height - intPenWidth);
|
||||
path.AddArc(new Rectangle(-1 * intPenWidth, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), 0, 90);
|
||||
path.AddLine(0, this.Height, 0, 0);
|
||||
path.AddArc(new Rectangle(-1 * intPenWidth, 0, intPenWidth * 2, intPenWidth * 2), 270, 90);
|
||||
path.CloseAllFigures();
|
||||
|
||||
linePath.AddArc(new Rectangle(-1 * intPenWidth / 2 - 1, intPenWidth / 2 + 1, intPenWidth, intPenWidth), 269, 91);
|
||||
//linePath.AddLine(intPenWidth / 2, intPenWidth, intPenWidth / 2, this.Height - intPenWidth);
|
||||
linePath.AddArc(new Rectangle(-1 * intPenWidth / 2 - 1, this.Height - intPenWidth - intPenWidth / 2 - 1, intPenWidth, intPenWidth), -1, 91);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1 * intPenWidth, 0, intPenWidth * 2, intPenWidth * 2), startAngle = 270, sweepAngle = 90 });
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1 * intPenWidth, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), startAngle = 0, sweepAngle = 90 });
|
||||
break;
|
||||
case ConduitStyle.Vertical_Right_Right:
|
||||
path.AddLine(this.Width, 0, this.Width, this.Height);
|
||||
path.AddArc(new Rectangle(-1, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), 90, 90);
|
||||
path.AddLine(0, this.Height - intPenWidth, 0, intPenWidth);
|
||||
path.AddArc(new Rectangle(-1, 0, intPenWidth * 2, intPenWidth * 2), 180, 90);
|
||||
path.CloseAllFigures();
|
||||
|
||||
linePath.AddArc(new Rectangle(intPenWidth / 2, intPenWidth / 2 + 1, intPenWidth, intPenWidth), 271, -91);
|
||||
//linePath.AddLine(intPenWidth / 2, intPenWidth, intPenWidth / 2, this.Height - intPenWidth);
|
||||
linePath.AddArc(new Rectangle(intPenWidth / 2, this.Height - intPenWidth - intPenWidth / 2 - 1, intPenWidth, intPenWidth), 180, -91);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1, 0, intPenWidth * 2, intPenWidth * 2), startAngle = 180, sweepAngle = 90 });
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(-1, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), startAngle = 90, sweepAngle = 90 });
|
||||
break;
|
||||
case ConduitStyle.Vertical_Tilt_Left:
|
||||
double angleLeft = Math.Atan((this.ClientRectangle.Width - conduitWidth) / (double)this.ClientRectangle.Height);
|
||||
angleLeft = angleLeft / Math.PI * 180f;
|
||||
path.AddArc(new Rectangle(this.ClientRectangle.Left - 1, ClientRectangle.Top - conduitWidth, conduitWidth * 2, conduitWidth * 2), 180, -1 * (float)angleLeft);
|
||||
path.AddLine(new Point(this.ClientRectangle.Right - conduitWidth, this.ClientRectangle.Bottom), new Point(this.ClientRectangle.Right, this.ClientRectangle.Bottom));
|
||||
path.AddArc(new Rectangle(this.ClientRectangle.Right - conduitWidth * 2, this.ClientRectangle.Bottom - conduitWidth, conduitWidth * 2, conduitWidth * 2), 0, -1 * (float)angleLeft);
|
||||
path.AddLine(new Point(this.ClientRectangle.Left + conduitWidth, this.ClientRectangle.Top), new Point(this.ClientRectangle.Left, this.ClientRectangle.Top));
|
||||
path.CloseAllFigures();
|
||||
|
||||
|
||||
linePath.AddArc(new Rectangle(this.ClientRectangle.Left + conduitWidth / 2, this.ClientRectangle.Top - conduitWidth / 2, conduitWidth, conduitWidth), 185, -1 * (float)angleLeft - 5);
|
||||
linePath.AddArc(new Rectangle(this.ClientRectangle.Right - conduitWidth - conduitWidth / 2, this.ClientRectangle.Bottom - conduitWidth / 2, conduitWidth, conduitWidth), -1 * (float)angleLeft, (float)angleLeft);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Left - 1, ClientRectangle.Top - conduitWidth, conduitWidth * 2, conduitWidth * 2), startAngle = 180, sweepAngle = -1 * (float)angleLeft });
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - conduitWidth * 2, this.ClientRectangle.Bottom - conduitWidth, conduitWidth * 2, conduitWidth * 2), startAngle = 0, sweepAngle = -1 * (float)angleLeft });
|
||||
|
||||
tileLine.Add(new Point[]
|
||||
{
|
||||
new Point((int)(this.ClientRectangle.Left + conduitWidth),this.ClientRectangle.Top),
|
||||
new Point((int)(this.ClientRectangle.Right-conduitWidth+Math.Cos(Math.PI * (angleLeft / 180.00F)) * conduitWidth),(int)(this.ClientRectangle.Bottom-Math.Sin(Math.PI * (angleLeft / 180.00F)) * conduitWidth))
|
||||
});
|
||||
tileLine.Add(new Point[]
|
||||
{
|
||||
new Point((int)(this.ClientRectangle.Left-1+conduitWidth-Math.Cos(Math.PI * (angleLeft / 180.00F)) * conduitWidth),(int)(this.ClientRectangle.Top+Math.Sin(Math.PI * (angleLeft / 180.00F)) * conduitWidth)),
|
||||
new Point(this.ClientRectangle.Right-conduitWidth,this.ClientRectangle.Bottom)
|
||||
});
|
||||
break;
|
||||
case ConduitStyle.Vertical_Tilt_Right:
|
||||
double angleRight = Math.Atan((this.ClientRectangle.Width - conduitWidth) / (double)this.ClientRectangle.Height);
|
||||
angleRight = angleRight / Math.PI * 180f;
|
||||
path.AddArc(new Rectangle(this.ClientRectangle.Right - conduitWidth * 2, ClientRectangle.Top - conduitWidth, conduitWidth * 2, conduitWidth * 2), 0, (float)angleRight);
|
||||
path.AddLine(new Point(this.ClientRectangle.Left + conduitWidth, this.ClientRectangle.Bottom), new Point(this.ClientRectangle.Left, this.ClientRectangle.Bottom));
|
||||
path.AddArc(new Rectangle(this.ClientRectangle.Left - 1, this.ClientRectangle.Bottom - conduitWidth, conduitWidth * 2, conduitWidth * 2), 180, (float)angleRight);
|
||||
path.AddLine(new Point(this.ClientRectangle.Right - conduitWidth, this.ClientRectangle.Top), new Point(this.ClientRectangle.Right, this.ClientRectangle.Top));
|
||||
path.CloseAllFigures();
|
||||
|
||||
|
||||
linePath.AddArc(new Rectangle(this.ClientRectangle.Right - conduitWidth - conduitWidth / 2, this.ClientRectangle.Top - conduitWidth / 2, conduitWidth, conduitWidth), -5, (float)angleRight + 5);
|
||||
linePath.AddArc(new Rectangle(this.ClientRectangle.Left + conduitWidth / 2, this.ClientRectangle.Bottom - conduitWidth / 2, conduitWidth, conduitWidth), 180 + (float)angleRight, -1 * (float)angleRight);
|
||||
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Right - conduitWidth * 2, ClientRectangle.Top - conduitWidth, conduitWidth * 2, conduitWidth * 2), startAngle = 0, sweepAngle = (float)angleRight });
|
||||
lstArcs.Add(new ArcEntity() { rect = new Rectangle(this.ClientRectangle.Left - 1, this.ClientRectangle.Bottom - conduitWidth, conduitWidth * 2, conduitWidth * 2), startAngle = 180, sweepAngle = (float)angleRight });
|
||||
|
||||
tileLine.Add(new Point[]
|
||||
{
|
||||
new Point((int)(this.ClientRectangle.Right - conduitWidth),this.ClientRectangle.Top),
|
||||
new Point((int)(this.ClientRectangle.Left + conduitWidth - Math.Cos(Math.PI * (angleRight / 180.00F)) * conduitWidth),(int)(this.ClientRectangle.Bottom-Math.Sin(Math.PI * (angleRight / 180.00F)) * conduitWidth))
|
||||
});
|
||||
tileLine.Add(new Point[]
|
||||
{
|
||||
new Point((int)(this.ClientRectangle.Right - conduitWidth+Math.Cos(Math.PI * (angleRight / 180.00F)) * conduitWidth),(int)(this.ClientRectangle.Top+Math.Sin(Math.PI * (angleRight / 180.00F)) * conduitWidth)),
|
||||
new Point(this.ClientRectangle.Left + conduitWidth,this.ClientRectangle.Bottom)
|
||||
});
|
||||
break;
|
||||
#endregion
|
||||
}
|
||||
base.Region = new Region(path);
|
||||
g.FillPath(new SolidBrush(conduitColor), path);
|
||||
|
||||
//渐变色
|
||||
int _intPenWidth = intPenWidth;
|
||||
if (conduitStyle.ToString().Contains("Tilt"))
|
||||
{
|
||||
_intPenWidth = conduitWidth;
|
||||
}
|
||||
int intCount = _intPenWidth / 2 / 4;
|
||||
for (int i = 0; i < intCount; i++)
|
||||
{
|
||||
int _penWidth = _intPenWidth / 2 - 4 * i;
|
||||
if (_penWidth <= 0)
|
||||
_penWidth = 1;
|
||||
g.DrawPath(new Pen(new SolidBrush(Color.FromArgb(40, Color.White.R, Color.White.G, Color.White.B)), _penWidth), linePath);
|
||||
if (_penWidth == 1)
|
||||
break;
|
||||
}
|
||||
|
||||
g.SetGDIHigh();
|
||||
//使用抗锯齿画圆角
|
||||
foreach (var item in lstArcs)
|
||||
{
|
||||
g.DrawArc(new Pen(new SolidBrush(this.BackColor)), item.rect, item.startAngle, item.sweepAngle);
|
||||
}
|
||||
|
||||
if (tileLine.Count > 0)
|
||||
{
|
||||
foreach (var item in tileLine)
|
||||
{
|
||||
g.DrawLine(new Pen(new SolidBrush(this.BackColor)), item[0], item[1]);
|
||||
}
|
||||
}
|
||||
|
||||
//液体流动
|
||||
if (LiquidDirection != LiquidDirection.None)
|
||||
{
|
||||
Pen p = new Pen(new SolidBrush(liquidColor), 4);
|
||||
p.DashPattern = new float[] { 6, 6 };
|
||||
p.DashOffset = intLineLeft * (LiquidDirection == LiquidDirection.Forward ? -1 : 1);
|
||||
g.DrawPath(p, linePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Class ArcEntity.
|
||||
/// </summary>
|
||||
class ArcEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the rect.
|
||||
/// </summary>
|
||||
/// <value>The rect.</value>
|
||||
public Rectangle rect { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the start angle.
|
||||
/// </summary>
|
||||
/// <value>The start angle.</value>
|
||||
public float startAngle { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the sweep angle.
|
||||
/// </summary>
|
||||
/// <value>The sweep angle.</value>
|
||||
public float sweepAngle { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enum LiquidDirection
|
||||
/// </summary>
|
||||
public enum LiquidDirection
|
||||
{
|
||||
/// <summary>
|
||||
/// The none
|
||||
/// </summary>
|
||||
None,
|
||||
/// <summary>
|
||||
/// The forward
|
||||
/// </summary>
|
||||
Forward,
|
||||
/// <summary>
|
||||
/// The backward
|
||||
/// </summary>
|
||||
Backward
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 管道样式Enum ConduitStyle
|
||||
/// </summary>
|
||||
public enum ConduitStyle
|
||||
{
|
||||
/// <summary>
|
||||
/// 直线 The horizontal none none
|
||||
/// </summary>
|
||||
Horizontal_None_None,
|
||||
/// <summary>
|
||||
/// 左上The horizontal up none
|
||||
/// </summary>
|
||||
Horizontal_Up_None,
|
||||
/// <summary>
|
||||
/// 左下The horizontal down none
|
||||
/// </summary>
|
||||
Horizontal_Down_None,
|
||||
/// <summary>
|
||||
/// 右上The horizontal none up
|
||||
/// </summary>
|
||||
Horizontal_None_Up,
|
||||
/// <summary>
|
||||
/// 右下The horizontal none down
|
||||
/// </summary>
|
||||
Horizontal_None_Down,
|
||||
/// <summary>
|
||||
/// 左下右上The horizontal down up
|
||||
/// </summary>
|
||||
Horizontal_Down_Up,
|
||||
/// <summary>
|
||||
/// 左上右下The horizontal up down
|
||||
/// </summary>
|
||||
Horizontal_Up_Down,
|
||||
/// <summary>
|
||||
/// 左上,右上The horizontal up up
|
||||
/// </summary>
|
||||
Horizontal_Up_Up,
|
||||
/// <summary>
|
||||
/// 左下右下The horizontal down down
|
||||
/// </summary>
|
||||
Horizontal_Down_Down,
|
||||
/// <summary>
|
||||
/// 向上倾斜The horizontal tilt up
|
||||
/// </summary>
|
||||
Horizontal_Tilt_Up,
|
||||
/// <summary>
|
||||
/// 向下倾斜The horizontal tilt down
|
||||
/// </summary>
|
||||
Horizontal_Tilt_Down,
|
||||
|
||||
/// <summary>
|
||||
/// 竖线The vertical none none
|
||||
/// </summary>
|
||||
Vertical_None_None,
|
||||
/// <summary>
|
||||
/// 上左The vertical left none
|
||||
/// </summary>
|
||||
Vertical_Left_None,
|
||||
/// <summary>
|
||||
/// 上右The vertical right none
|
||||
/// </summary>
|
||||
Vertical_Right_None,
|
||||
/// <summary>
|
||||
/// 下左The vertical none left
|
||||
/// </summary>
|
||||
Vertical_None_Left,
|
||||
/// <summary>
|
||||
/// 下右The vertical none right
|
||||
/// </summary>
|
||||
Vertical_None_Right,
|
||||
/// <summary>
|
||||
/// 上左下右The vertical left right
|
||||
/// </summary>
|
||||
Vertical_Left_Right,
|
||||
/// <summary>
|
||||
/// 上右下左The vertical right left
|
||||
/// </summary>
|
||||
Vertical_Right_Left,
|
||||
/// <summary>
|
||||
/// 上左下左The vertical left left
|
||||
/// </summary>
|
||||
Vertical_Left_Left,
|
||||
/// <summary>
|
||||
/// 上右下右The vertical right left
|
||||
/// </summary>
|
||||
Vertical_Right_Right,
|
||||
/// <summary>
|
||||
/// 向左倾斜The vertical tilt
|
||||
/// </summary>
|
||||
Vertical_Tilt_Left,
|
||||
/// <summary>
|
||||
/// 向右倾斜The vertical tilt right
|
||||
/// </summary>
|
||||
Vertical_Tilt_Right
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : HZH_Controls
|
||||
// Created : 2019-09-05
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="UCConveyor.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 System.ComponentModel;
|
||||
|
||||
namespace HZH_Controls.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UCConveyor.
|
||||
/// Implements the <see cref="System.Windows.Forms.UserControl" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Windows.Forms.UserControl" />
|
||||
public class UCConveyor : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// The conveyor color
|
||||
/// </summary>
|
||||
private Color conveyorColor = Color.FromArgb(255, 77, 59);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the conveyor.
|
||||
/// </summary>
|
||||
/// <value>The color of the conveyor.</value>
|
||||
[Description("传送带颜色"), Category("自定义")]
|
||||
public Color ConveyorColor
|
||||
{
|
||||
get { return conveyorColor; }
|
||||
set
|
||||
{
|
||||
conveyorColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The inclination
|
||||
/// </summary>
|
||||
private double inclination = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the inclination.
|
||||
/// </summary>
|
||||
/// <value>The inclination.</value>
|
||||
[Description("传送带角度(-90<=value<=90)"), Category("自定义")]
|
||||
public double Inclination
|
||||
{
|
||||
get { return inclination; }
|
||||
set
|
||||
{
|
||||
if (value > 90 || value < -90)
|
||||
return;
|
||||
inclination = value;
|
||||
ResetWorkingRect();
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The conveyor height
|
||||
/// </summary>
|
||||
private int conveyorHeight = 50;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the height of the conveyor.
|
||||
/// </summary>
|
||||
/// <value>The height of the conveyor.</value>
|
||||
[Description("传送带高度"), Category("自定义")]
|
||||
public int ConveyorHeight
|
||||
{
|
||||
get { return conveyorHeight; }
|
||||
set
|
||||
{
|
||||
conveyorHeight = value;
|
||||
ResetWorkingRect();
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The conveyor direction
|
||||
/// </summary>
|
||||
private ConveyorDirection conveyorDirection = ConveyorDirection.Forward;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the conveyor direction.
|
||||
/// </summary>
|
||||
/// <value>The conveyor direction.</value>
|
||||
[Description("传送带运行方向"), Category("自定义")]
|
||||
public ConveyorDirection ConveyorDirection
|
||||
{
|
||||
get { return conveyorDirection; }
|
||||
set
|
||||
{
|
||||
conveyorDirection = value;
|
||||
if (value == HZH_Controls.Controls.ConveyorDirection.None)
|
||||
{
|
||||
m_timer.Enabled = false;
|
||||
Refresh();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_timer.Enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The liquid speed
|
||||
/// </summary>
|
||||
private int conveyorSpeed = 100;
|
||||
|
||||
/// <summary>
|
||||
/// 传送带运行速度,越小,速度越快Gets or sets the ConveyorSpeed.
|
||||
/// </summary>
|
||||
/// <value>The liquid speed.</value>
|
||||
[Description("传送带运行速度,越小,速度越快"), Category("自定义")]
|
||||
public int ConveyorSpeed
|
||||
{
|
||||
get { return conveyorSpeed; }
|
||||
set
|
||||
{
|
||||
if (value <= 0)
|
||||
return;
|
||||
conveyorSpeed = value;
|
||||
m_timer.Interval = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The m working rect
|
||||
/// </summary>
|
||||
Rectangle m_workingRect;
|
||||
/// <summary>
|
||||
/// The int line left
|
||||
/// </summary>
|
||||
int intLineLeft = 0;
|
||||
/// <summary>
|
||||
/// The m timer
|
||||
/// </summary>
|
||||
Timer m_timer;
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UCConveyor" /> class.
|
||||
/// </summary>
|
||||
public UCConveyor()
|
||||
{
|
||||
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.SizeChanged += UCConveyor_SizeChanged;
|
||||
this.Size = new Size(300, 50);
|
||||
m_timer = new Timer();
|
||||
m_timer.Interval = 100;
|
||||
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 += 2;
|
||||
if (intLineLeft > 12)
|
||||
intLineLeft = 0;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the SizeChanged event of the UCConveyor 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 UCConveyor_SizeChanged(object sender, EventArgs e)
|
||||
{
|
||||
ResetWorkingRect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the working rect.
|
||||
/// </summary>
|
||||
private void ResetWorkingRect()
|
||||
{
|
||||
if (inclination == 90 || inclination == -90)
|
||||
{
|
||||
m_workingRect = new Rectangle((this.Width - conveyorHeight) / 2, 1, conveyorHeight, this.Height - 2);
|
||||
}
|
||||
else if (inclination == 0)
|
||||
{
|
||||
m_workingRect = new Rectangle(1, (this.Height - conveyorHeight) / 2 + 1, this.Width - 2, conveyorHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
//根据角度计算需要的高度
|
||||
int intHeight = (int)(Math.Tan(Math.PI * (Math.Abs(inclination) / 180.00000)) * (this.Width));
|
||||
if (intHeight >= this.Height)
|
||||
intHeight = this.Height;
|
||||
|
||||
int intWidth = (int)(intHeight / (Math.Tan(Math.PI * (Math.Abs(inclination) / 180.00000))));
|
||||
intHeight += conveyorHeight;
|
||||
if (intHeight >= this.Height)
|
||||
intHeight = this.Height;
|
||||
m_workingRect = new Rectangle((this.Width - intWidth) / 2 + 1, (this.Height - intHeight) / 2 + 1, intWidth - 2, intHeight - 2);
|
||||
}
|
||||
}
|
||||
|
||||
/// <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;
|
||||
g.SetGDIHigh();
|
||||
//g.FillRectangle(new SolidBrush(Color.FromArgb(100, conveyorColor)), m_workingRect);
|
||||
|
||||
//轴
|
||||
//左端
|
||||
var rectLeft = new Rectangle(m_workingRect.Left + 5, (inclination >= 0 ? (m_workingRect.Bottom - conveyorHeight) : m_workingRect.Top) + 5, conveyorHeight - 10, conveyorHeight - 10);
|
||||
g.FillEllipse(new SolidBrush(conveyorColor), rectLeft);
|
||||
g.FillEllipse(new SolidBrush(Color.White), new Rectangle(rectLeft.Left + (rectLeft.Width - 6) / 2, rectLeft.Top + (rectLeft.Height - 6) / 2, 6, 6));
|
||||
//右端
|
||||
var rectRight = new Rectangle(m_workingRect.Right - conveyorHeight + 5, (inclination >= 0 ? (m_workingRect.Top) : (m_workingRect.Bottom - conveyorHeight)) + 5, conveyorHeight - 10, conveyorHeight - 10);
|
||||
g.FillEllipse(new SolidBrush(conveyorColor), rectRight);
|
||||
g.FillEllipse(new SolidBrush(Color.White), new Rectangle(rectRight.Left + (rectRight.Width - 6) / 2, rectRight.Top + (rectRight.Height - 6) / 2, 6, 6));
|
||||
|
||||
//传送带
|
||||
//左端
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
GraphicsPath pathRegion = new GraphicsPath();
|
||||
path.AddArc(new Rectangle(m_workingRect.Left + 3, (inclination >= 0 ? (m_workingRect.Bottom - conveyorHeight) : m_workingRect.Top) + 3, conveyorHeight - 6, conveyorHeight - 6), 90F - (float)inclination, 180F);
|
||||
pathRegion.AddArc(new Rectangle(m_workingRect.Left, (inclination >= 0 ? (m_workingRect.Bottom - conveyorHeight) : m_workingRect.Top), conveyorHeight, conveyorHeight), 90F - (float)inclination, 180F);
|
||||
//右端
|
||||
path.AddArc(new Rectangle(m_workingRect.Right - conveyorHeight + 3, (inclination >= 0 ? (m_workingRect.Top) : (m_workingRect.Bottom - conveyorHeight)) + 3, conveyorHeight - 6, conveyorHeight - 6), 270 - (float)inclination, 180F);
|
||||
pathRegion.AddArc(new Rectangle(m_workingRect.Right - conveyorHeight, (inclination >= 0 ? (m_workingRect.Top) : (m_workingRect.Bottom - conveyorHeight)), conveyorHeight, conveyorHeight), 270 - (float)inclination, 180F);
|
||||
path.CloseAllFigures();
|
||||
|
||||
base.Region = new System.Drawing.Region(pathRegion);
|
||||
|
||||
g.DrawPath(new Pen(new SolidBrush(conveyorColor), 3), path);
|
||||
|
||||
//液体流动
|
||||
if (ConveyorDirection != ConveyorDirection.None)
|
||||
{
|
||||
Pen p = new Pen(new SolidBrush(Color.FromArgb(150, this.BackColor)), 4);
|
||||
p.DashPattern = new float[] { 6, 6 };
|
||||
p.DashOffset = intLineLeft * (ConveyorDirection == ConveyorDirection.Forward ? -1 : 1);
|
||||
g.DrawPath(p, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enum ConveyorDirection
|
||||
/// </summary>
|
||||
public enum ConveyorDirection
|
||||
{
|
||||
/// <summary>
|
||||
/// The none
|
||||
/// </summary>
|
||||
None,
|
||||
/// <summary>
|
||||
/// The forward
|
||||
/// </summary>
|
||||
Forward,
|
||||
/// <summary>
|
||||
/// The backward
|
||||
/// </summary>
|
||||
Backward
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : HZH_Controls
|
||||
// Created : 2019-09-10
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="UCAlarmLamp.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 System.ComponentModel;
|
||||
|
||||
namespace HZH_Controls.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UCAlarmLamp.
|
||||
/// Implements the <see cref="System.Windows.Forms.UserControl" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Windows.Forms.UserControl" />
|
||||
public class UCAlarmLamp : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// The lamp color
|
||||
/// </summary>
|
||||
private Color[] lampColor = new Color[] { Color.FromArgb(255, 77, 59) };
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the lamp.
|
||||
/// </summary>
|
||||
/// <value>The color of the lamp.</value>
|
||||
[Description("灯颜色,当需要闪烁时,至少需要2个及以上颜色,不需要闪烁则至少需要1个颜色"), Category("自定义")]
|
||||
public Color[] LampColor
|
||||
{
|
||||
get { return lampColor; }
|
||||
set
|
||||
{
|
||||
if (value == null || value.Length <= 0)
|
||||
return;
|
||||
lampColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The lampstand
|
||||
/// </summary>
|
||||
private Color lampstand = Color.FromArgb(105, 105, 105);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the lampstand.
|
||||
/// </summary>
|
||||
/// <value>The lampstand.</value>
|
||||
[Description("灯座颜色"), Category("自定义")]
|
||||
public Color Lampstand
|
||||
{
|
||||
get { return lampstand; }
|
||||
set { lampstand = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The twinkle speed
|
||||
/// </summary>
|
||||
private int twinkleSpeed = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the twinkle speed.
|
||||
/// </summary>
|
||||
/// <value>The twinkle speed.</value>
|
||||
[Description("闪烁间隔时间(毫秒),当为0时不闪烁"), Category("自定义")]
|
||||
public int TwinkleSpeed
|
||||
{
|
||||
get { return twinkleSpeed; }
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
return;
|
||||
twinkleSpeed = value;
|
||||
if (value == 0 || lampColor.Length <= 1)
|
||||
{
|
||||
timer.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
intColorIndex = 0;
|
||||
timer.Interval = value;
|
||||
timer.Enabled = true;
|
||||
}
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The timer
|
||||
/// </summary>
|
||||
Timer timer;
|
||||
/// <summary>
|
||||
/// The int color index
|
||||
/// </summary>
|
||||
int intColorIndex = 0;
|
||||
/// <summary>
|
||||
/// The m rect working
|
||||
/// </summary>
|
||||
Rectangle m_rectWorking;
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UCAlarmLamp" /> class.
|
||||
/// </summary>
|
||||
public UCAlarmLamp()
|
||||
{
|
||||
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||
this.SetStyle(ControlStyles.DoubleBuffer, true);
|
||||
this.SetStyle(ControlStyles.ResizeRedraw, true);
|
||||
this.SetStyle(ControlStyles.Selectable, true);
|
||||
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
|
||||
this.SetStyle(ControlStyles.UserPaint, true);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.SizeChanged += UCAlarmLamp_SizeChanged;
|
||||
this.Size = new Size(50, 50);
|
||||
timer = new Timer();
|
||||
timer.Interval = 200;
|
||||
timer.Tick += timer_Tick;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the SizeChanged event of the UCAlarmLamp 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 UCAlarmLamp_SizeChanged(object sender, EventArgs e)
|
||||
{
|
||||
m_rectWorking = new Rectangle(10, 0, this.Width - 20, this.Height);
|
||||
}
|
||||
/// <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)
|
||||
{
|
||||
intColorIndex++;
|
||||
if (intColorIndex >= lampColor.Length)
|
||||
intColorIndex = 0;
|
||||
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;
|
||||
g.SetGDIHigh();
|
||||
|
||||
Color c1 = lampColor[intColorIndex];
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
path.AddLine(new Point(m_rectWorking.Left, m_rectWorking.Bottom), new Point(m_rectWorking.Left, m_rectWorking.Top + m_rectWorking.Width));
|
||||
path.AddArc(new Rectangle(m_rectWorking.Left, m_rectWorking.Top, m_rectWorking.Width, m_rectWorking.Width), 180f, 180f);
|
||||
path.AddLine(new Point(m_rectWorking.Right, m_rectWorking.Top + m_rectWorking.Width), new Point(m_rectWorking.Right, m_rectWorking.Bottom));
|
||||
path.CloseAllFigures();
|
||||
g.FillPath(new SolidBrush(c1), path);
|
||||
|
||||
g.FillRectangle(new SolidBrush(lampstand), new Rectangle(5, m_rectWorking.Bottom - 19, this.Width - 10, 10));
|
||||
g.FillRectangle(new SolidBrush(lampstand), new Rectangle(0, m_rectWorking.Bottom - 10, this.Width, 10));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : HZH_Controls
|
||||
// Created : 2019-09-09
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="UCSignalLamp.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 System.ComponentModel;
|
||||
|
||||
namespace HZH_Controls.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UCSignalLamp.
|
||||
/// Implements the <see cref="System.Windows.Forms.UserControl" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Windows.Forms.UserControl" />
|
||||
public class UCSignalLamp : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// The is show border
|
||||
/// </summary>
|
||||
private bool isShowBorder = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this instance is show border.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if this instance is show border; otherwise, <c>false</c>.</value>
|
||||
[Description("是否显示边框"), Category("自定义")]
|
||||
public bool IsShowBorder
|
||||
{
|
||||
get { return isShowBorder; }
|
||||
set
|
||||
{
|
||||
isShowBorder = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The lamp color
|
||||
/// </summary>
|
||||
private Color[] lampColor = new Color[] { Color.FromArgb(255, 77, 59) };
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the lamp.
|
||||
/// </summary>
|
||||
/// <value>The color of the lamp.</value>
|
||||
[Description("灯颜色,当需要闪烁时,至少需要2个及以上颜色,不需要闪烁则至少需要1个颜色"), Category("自定义")]
|
||||
public Color[] LampColor
|
||||
{
|
||||
get { return lampColor; }
|
||||
set
|
||||
{
|
||||
if (value == null || value.Length <= 0)
|
||||
return;
|
||||
lampColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The is highlight
|
||||
/// </summary>
|
||||
private bool isHighlight = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this instance is highlight.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if this instance is highlight; otherwise, <c>false</c>.</value>
|
||||
[Description("是否高亮显示"), Category("自定义")]
|
||||
public bool IsHighlight
|
||||
{
|
||||
get { return isHighlight; }
|
||||
set
|
||||
{
|
||||
isHighlight = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The twinkle speed
|
||||
/// </summary>
|
||||
private int twinkleSpeed = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the twinkle speed.
|
||||
/// </summary>
|
||||
/// <value>The twinkle speed.</value>
|
||||
[Description("闪烁间隔时间(毫秒),当为0时不闪烁"), Category("自定义")]
|
||||
public int TwinkleSpeed
|
||||
{
|
||||
get { return twinkleSpeed; }
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
return;
|
||||
twinkleSpeed = value;
|
||||
if (value == 0 || lampColor.Length <= 1)
|
||||
{
|
||||
timer.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
intColorIndex = 0;
|
||||
timer.Interval = value;
|
||||
timer.Enabled = true;
|
||||
}
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The timer
|
||||
/// </summary>
|
||||
Timer timer;
|
||||
/// <summary>
|
||||
/// The int color index
|
||||
/// </summary>
|
||||
int intColorIndex = 0;
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UCSignalLamp" /> class.
|
||||
/// </summary>
|
||||
public UCSignalLamp()
|
||||
{
|
||||
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(50, 50);
|
||||
this.SizeChanged += UCSignalLamp_SizeChanged;
|
||||
timer = new Timer();
|
||||
timer.Interval = 200;
|
||||
timer.Tick += timer_Tick;
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
intColorIndex++;
|
||||
if (intColorIndex >= lampColor.Length)
|
||||
intColorIndex = 0;
|
||||
Refresh();
|
||||
}
|
||||
/// <summary>
|
||||
/// Handles the SizeChanged event of the UCSignalLamp 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 UCSignalLamp_SizeChanged(object sender, EventArgs e)
|
||||
{
|
||||
var maxSize = Math.Min(this.Width, this.Height);
|
||||
if (this.Width != maxSize)
|
||||
this.Width = maxSize;
|
||||
if (this.Height != maxSize)
|
||||
this.Height = maxSize;
|
||||
}
|
||||
|
||||
/// <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;
|
||||
g.SetGDIHigh();
|
||||
|
||||
Color c1 = lampColor[intColorIndex];
|
||||
g.FillEllipse(new SolidBrush(c1), new Rectangle(this.ClientRectangle.Location, this.ClientRectangle.Size - new Size(1, 1)));
|
||||
|
||||
if (isHighlight)
|
||||
{
|
||||
GraphicsPath gp = new GraphicsPath();
|
||||
|
||||
Rectangle rec = new Rectangle(5, 5, this.Width - 10 - 1, this.Height - 10 - 1);
|
||||
gp.AddEllipse(rec);
|
||||
|
||||
Color[] surroundColor = new Color[] { c1 };
|
||||
PathGradientBrush pb = new PathGradientBrush(gp);
|
||||
pb.CenterColor = Color.White;
|
||||
pb.SurroundColors = surroundColor;
|
||||
g.FillPath(pb, gp);
|
||||
}
|
||||
|
||||
if (isShowBorder)
|
||||
{
|
||||
g.DrawEllipse(new Pen(new SolidBrush(this.BackColor), 2), new Rectangle(4, 4, this.Width - 1 - 8, this.Height - 1 - 8));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,434 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : HZH_Controls
|
||||
// Created : 2019-09-03
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="UCMeter.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 System.ComponentModel;
|
||||
|
||||
namespace HZH_Controls.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UCMeter.
|
||||
/// Implements the <see cref="System.Windows.Forms.UserControl" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Windows.Forms.UserControl" />
|
||||
public class UCMeter : UserControl
|
||||
{
|
||||
private int splitCount = 10;
|
||||
/// <summary>
|
||||
/// Gets or sets the split count.
|
||||
/// </summary>
|
||||
/// <value>The split count.</value>
|
||||
[Description("分隔刻度数量,>1"), Category("自定义")]
|
||||
public int SplitCount
|
||||
{
|
||||
get { return splitCount; }
|
||||
set
|
||||
{
|
||||
if (value < 1)
|
||||
return;
|
||||
splitCount = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private int meterDegrees = 150;
|
||||
/// <summary>
|
||||
/// Gets or sets the meter degrees.
|
||||
/// </summary>
|
||||
/// <value>The meter degrees.</value>
|
||||
[Description("表盘跨度角度,0-360"), Category("自定义")]
|
||||
public int MeterDegrees
|
||||
{
|
||||
get { return meterDegrees; }
|
||||
set
|
||||
{
|
||||
if (value > 360 || value <= 0)
|
||||
return;
|
||||
meterDegrees = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private decimal minValue = 0;
|
||||
/// <summary>
|
||||
/// Gets or sets the minimum value.
|
||||
/// </summary>
|
||||
/// <value>The minimum value.</value>
|
||||
[Description("最小值,<MaxValue"), Category("自定义")]
|
||||
public decimal MinValue
|
||||
{
|
||||
get { return minValue; }
|
||||
set
|
||||
{
|
||||
if (value >= maxValue)
|
||||
return;
|
||||
minValue = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private decimal maxValue = 100;
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum value.
|
||||
/// </summary>
|
||||
/// <value>The maximum value.</value>
|
||||
[Description("最大值,>MinValue"), Category("自定义")]
|
||||
public decimal MaxValue
|
||||
{
|
||||
get { return maxValue; }
|
||||
set
|
||||
{
|
||||
if (value <= minValue)
|
||||
return;
|
||||
maxValue = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取或设置控件显示的文字的字体。
|
||||
/// </summary>
|
||||
/// <value>The font.</value>
|
||||
/// <PermissionSet>
|
||||
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||||
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
||||
/// <IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||||
/// </PermissionSet>
|
||||
[Description("刻度字体"), Category("自定义")]
|
||||
public override Font Font
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Font;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.Font = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private decimal m_value = 0;
|
||||
/// <summary>
|
||||
/// Gets or sets the value.
|
||||
/// </summary>
|
||||
/// <value>The value.</value>
|
||||
[Description("值,>=MinValue并且<=MaxValue"), Category("自定义")]
|
||||
public decimal Value
|
||||
{
|
||||
get { return m_value; }
|
||||
set
|
||||
{
|
||||
if (value < minValue || value > maxValue)
|
||||
return;
|
||||
m_value = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private MeterTextLocation textLocation = MeterTextLocation.None;
|
||||
/// <summary>
|
||||
/// Gets or sets the text location.
|
||||
/// </summary>
|
||||
/// <value>The text location.</value>
|
||||
[Description("值和固定文字显示位置"), Category("自定义")]
|
||||
public MeterTextLocation TextLocation
|
||||
{
|
||||
get { return textLocation; }
|
||||
set
|
||||
{
|
||||
textLocation = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private string fixedText;
|
||||
/// <summary>
|
||||
/// Gets or sets the fixed text.
|
||||
/// </summary>
|
||||
/// <value>The fixed text.</value>
|
||||
[Description("固定文字"), Category("自定义")]
|
||||
public string FixedText
|
||||
{
|
||||
get { return fixedText; }
|
||||
set
|
||||
{
|
||||
fixedText = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private Font textFont = DefaultFont;
|
||||
/// <summary>
|
||||
/// Gets or sets the text font.
|
||||
/// </summary>
|
||||
/// <value>The text font.</value>
|
||||
[Description("值和固定文字字体"), Category("自定义")]
|
||||
public Font TextFont
|
||||
{
|
||||
get { return textFont; }
|
||||
set
|
||||
{
|
||||
textFont = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private Color externalRoundColor = Color.FromArgb(255, 77, 59);
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the external round.
|
||||
/// </summary>
|
||||
/// <value>The color of the external round.</value>
|
||||
[Description("外圆颜色"), Category("自定义")]
|
||||
public Color ExternalRoundColor
|
||||
{
|
||||
get { return externalRoundColor; }
|
||||
set
|
||||
{
|
||||
externalRoundColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private Color insideRoundColor = Color.FromArgb(255, 77, 59);
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the inside round.
|
||||
/// </summary>
|
||||
/// <value>The color of the inside round.</value>
|
||||
[Description("内圆颜色"), Category("自定义")]
|
||||
public Color InsideRoundColor
|
||||
{
|
||||
get { return insideRoundColor; }
|
||||
set
|
||||
{
|
||||
insideRoundColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private Color boundaryLineColor = Color.FromArgb(255, 77, 59);
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the boundary line.
|
||||
/// </summary>
|
||||
/// <value>The color of the boundary line.</value>
|
||||
[Description("边界线颜色"), Category("自定义")]
|
||||
public Color BoundaryLineColor
|
||||
{
|
||||
get { return boundaryLineColor; }
|
||||
set
|
||||
{
|
||||
boundaryLineColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private Color scaleColor = Color.FromArgb(255, 77, 59);
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the scale.
|
||||
/// </summary>
|
||||
/// <value>The color of the scale.</value>
|
||||
[Description("刻度颜色"), Category("自定义")]
|
||||
public Color ScaleColor
|
||||
{
|
||||
get { return scaleColor; }
|
||||
set
|
||||
{
|
||||
scaleColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private Color scaleValueColor = Color.FromArgb(255, 77, 59);
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the scale value.
|
||||
/// </summary>
|
||||
/// <value>The color of the scale value.</value>
|
||||
[Description("刻度值文字颜色"), Category("自定义")]
|
||||
public Color ScaleValueColor
|
||||
{
|
||||
get { return scaleValueColor; }
|
||||
set
|
||||
{
|
||||
scaleValueColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private Color pointerColor = Color.FromArgb(255, 77, 59);
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the pointer.
|
||||
/// </summary>
|
||||
/// <value>The color of the pointer.</value>
|
||||
[Description("指针颜色"), Category("自定义")]
|
||||
public Color PointerColor
|
||||
{
|
||||
get { return pointerColor; }
|
||||
set
|
||||
{
|
||||
pointerColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private Color textColor = Color.FromArgb(255, 77, 59);
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the text.
|
||||
/// </summary>
|
||||
/// <value>The color of the text.</value>
|
||||
[Description("值和固定文字颜色"), Category("自定义")]
|
||||
public Color TextColor
|
||||
{
|
||||
get { return textColor; }
|
||||
set
|
||||
{
|
||||
textColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle m_rectWorking;
|
||||
public UCMeter()
|
||||
{
|
||||
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.SizeChanged += UCMeter1_SizeChanged;
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.Size = new Size(350, 200);
|
||||
}
|
||||
|
||||
void UCMeter1_SizeChanged(object sender, EventArgs e)
|
||||
{
|
||||
m_rectWorking = new Rectangle(10, 10, this.Width - 20, this.Height - 20);
|
||||
}
|
||||
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
var g = e.Graphics;
|
||||
g.SetGDIHigh();
|
||||
|
||||
//外圆
|
||||
float fltStartAngle = -90 - (meterDegrees) / 2 + 360;
|
||||
var r1 = new Rectangle(m_rectWorking.Location, new Size(m_rectWorking.Width, m_rectWorking.Width));
|
||||
g.DrawArc(new Pen(new SolidBrush(externalRoundColor), 1), r1, fltStartAngle, meterDegrees);
|
||||
//内圆
|
||||
var r2 = new Rectangle(m_rectWorking.Left + (m_rectWorking.Width - m_rectWorking.Width / 4) / 2, m_rectWorking.Top + (m_rectWorking.Width - m_rectWorking.Width / 4) / 2, m_rectWorking.Width / 4, m_rectWorking.Width / 4);
|
||||
g.DrawArc(new Pen(new SolidBrush(insideRoundColor), 1), r2, fltStartAngle, meterDegrees);
|
||||
|
||||
//边界线
|
||||
if (meterDegrees != 360)
|
||||
{
|
||||
float fltAngle = fltStartAngle - 180;
|
||||
|
||||
float intY = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - m_rectWorking.Width / 8) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
|
||||
float intX = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - m_rectWorking.Width / 8) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
|
||||
|
||||
float fltY1 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - (m_rectWorking.Width / 8 * Math.Sin(Math.PI * (fltAngle / 180.00F))));
|
||||
float fltX1 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - (m_rectWorking.Width / 8 * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
|
||||
|
||||
g.DrawLine(new Pen(new SolidBrush(boundaryLineColor), 1), new PointF(intX, intY), new PointF(fltX1, fltY1));
|
||||
g.DrawLine(new Pen(new SolidBrush(boundaryLineColor), 1), new PointF(m_rectWorking.Right - (fltX1 - m_rectWorking.Left), fltY1), new PointF(m_rectWorking.Right - (intX - m_rectWorking.Left), intY));
|
||||
}
|
||||
|
||||
//分割线
|
||||
int _splitCount = splitCount * 2;
|
||||
float fltSplitValue = (float)meterDegrees / (float)_splitCount;
|
||||
for (int i = 0; i <= _splitCount; i++)
|
||||
{
|
||||
float fltAngle = (fltStartAngle + fltSplitValue * i - 180) % 360;
|
||||
float fltY1 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
|
||||
float fltX1 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
|
||||
float fltY2 = 0;
|
||||
float fltX2 = 0;
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
fltY2 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 10) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
|
||||
fltX2 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 10) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
|
||||
if (!(meterDegrees == 360 && i == _splitCount))
|
||||
{
|
||||
decimal decValue = minValue + (maxValue - minValue) / _splitCount * i;
|
||||
var txtSize = g.MeasureString(decValue.ToString("0.##"), this.Font);
|
||||
float fltFY1 = (float)(m_rectWorking.Top - txtSize.Height / 2 + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 20) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
|
||||
float fltFX1 = (float)(m_rectWorking.Left - txtSize.Width / 2 + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 20) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
|
||||
g.DrawString(decValue.ToString("0.##"), Font, new SolidBrush(scaleValueColor), fltFX1, fltFY1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fltY2 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 5) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
|
||||
fltX2 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 5) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
|
||||
}
|
||||
g.DrawLine(new Pen(new SolidBrush(scaleColor), i % 2 == 0 ? 2 : 1), new PointF(fltX1, fltY1), new PointF(fltX2, fltY2));
|
||||
}
|
||||
|
||||
//值文字和固定文字
|
||||
if (textLocation != MeterTextLocation.None)
|
||||
{
|
||||
string str = m_value.ToString("0.##");
|
||||
var txtSize = g.MeasureString(str, textFont);
|
||||
float fltY = m_rectWorking.Top + m_rectWorking.Width / 4 - txtSize.Height / 2;
|
||||
float fltX = m_rectWorking.Left + m_rectWorking.Width / 2 - txtSize.Width / 2;
|
||||
g.DrawString(str, textFont, new SolidBrush(textColor), new PointF(fltX, fltY));
|
||||
|
||||
if (!string.IsNullOrEmpty(fixedText))
|
||||
{
|
||||
str = fixedText;
|
||||
txtSize = g.MeasureString(str, textFont);
|
||||
fltY = m_rectWorking.Top + m_rectWorking.Width / 4 + txtSize.Height / 2;
|
||||
fltX = m_rectWorking.Left + m_rectWorking.Width / 2 - txtSize.Width / 2;
|
||||
g.DrawString(str, textFont, new SolidBrush(textColor), new PointF(fltX, fltY));
|
||||
}
|
||||
}
|
||||
|
||||
//画指针
|
||||
g.FillEllipse(new SolidBrush(Color.FromArgb(100, pointerColor.R, pointerColor.G, pointerColor.B)), new Rectangle(m_rectWorking.Left + m_rectWorking.Width / 2 - 10, m_rectWorking.Top + m_rectWorking.Width / 2 - 10, 20, 20));
|
||||
g.FillEllipse(new SolidBrush(pointerColor), new Rectangle(m_rectWorking.Left + m_rectWorking.Width / 2 - 5, m_rectWorking.Top + m_rectWorking.Width / 2 - 5, 10, 10));
|
||||
float fltValueAngle = (fltStartAngle + ((float)(m_value - minValue) / (float)(maxValue - minValue)) * (float)meterDegrees - 180) % 360;
|
||||
float intValueY1 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 30) * Math.Sin(Math.PI * (fltValueAngle / 180.00F))));
|
||||
float intValueX1 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 30) * Math.Cos(Math.PI * (fltValueAngle / 180.00F)))));
|
||||
g.DrawLine(new Pen(new SolidBrush(pointerColor), 3), intValueX1, intValueY1, m_rectWorking.Left + m_rectWorking.Width / 2, m_rectWorking.Top + m_rectWorking.Width / 2);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enum MeterTextLocation
|
||||
/// </summary>
|
||||
public enum MeterTextLocation
|
||||
{
|
||||
/// <summary>
|
||||
/// The none
|
||||
/// </summary>
|
||||
None,
|
||||
/// <summary>
|
||||
/// The top
|
||||
/// </summary>
|
||||
Top,
|
||||
/// <summary>
|
||||
/// The bottom
|
||||
/// </summary>
|
||||
Bottom
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : HZH_Controls
|
||||
// Created : 2019-09-11
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="MindMappingItemEntity.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.Drawing;
|
||||
|
||||
namespace HZH_Controls.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Class MindMappingItemEntity.
|
||||
/// </summary>
|
||||
public class MindMappingItemEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the identifier.
|
||||
/// </summary>
|
||||
/// <value>The identifier.</value>
|
||||
public string ID { get; set; }
|
||||
/// <summary>
|
||||
/// The text
|
||||
/// </summary>
|
||||
private string _text;
|
||||
/// <summary>
|
||||
/// Gets or sets the text.
|
||||
/// </summary>
|
||||
/// <value>The text.</value>
|
||||
public string Text
|
||||
{
|
||||
get { return _text; }
|
||||
set
|
||||
{
|
||||
_text = value;
|
||||
ResetSize();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets or sets the data source.
|
||||
/// </summary>
|
||||
/// <value>The data source.</value>
|
||||
public object DataSource { get; set; }
|
||||
/// <summary>
|
||||
/// The childrens
|
||||
/// </summary>
|
||||
private MindMappingItemEntity[] _Childrens;
|
||||
/// <summary>
|
||||
/// Gets or sets the childrens.
|
||||
/// </summary>
|
||||
/// <value>The childrens.</value>
|
||||
public MindMappingItemEntity[] Childrens
|
||||
{
|
||||
get { return _Childrens; }
|
||||
set
|
||||
{
|
||||
_Childrens = value;
|
||||
if (value != null && value.Length > 0)
|
||||
{
|
||||
value.ToList().ForEach(p => { if (p != null) { p.ParentItem = this; } });
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The back color
|
||||
/// </summary>
|
||||
private Color? backColor;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the back.
|
||||
/// </summary>
|
||||
/// <value>The color of the back.</value>
|
||||
public Color? BackColor
|
||||
{
|
||||
get { return backColor; }
|
||||
set { backColor = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The font
|
||||
/// </summary>
|
||||
private Font font = new Font("微软雅黑", 10);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the font.
|
||||
/// </summary>
|
||||
/// <value>The font.</value>
|
||||
public Font Font
|
||||
{
|
||||
get { return font; }
|
||||
set
|
||||
{
|
||||
font = value;
|
||||
ResetSize();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The fore color
|
||||
/// </summary>
|
||||
private Color foreColor = Color.Black;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the fore.
|
||||
/// </summary>
|
||||
/// <value>The color of the fore.</value>
|
||||
public Color ForeColor
|
||||
{
|
||||
get { return foreColor; }
|
||||
set { foreColor = value; }
|
||||
}
|
||||
/// <summary>
|
||||
/// The is expansion
|
||||
/// </summary>
|
||||
private bool _IsExpansion = false;
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the instance is expanded.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if this instance is expansion; otherwise, <c>false</c>.</value>
|
||||
public bool IsExpansion
|
||||
{
|
||||
get
|
||||
{
|
||||
return _IsExpansion;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == _IsExpansion)
|
||||
return;
|
||||
_IsExpansion = value;
|
||||
if (!value && _Childrens != null && _Childrens.Length > 0)
|
||||
{
|
||||
_Childrens.ToList().ForEach(p => { if (p != null) { p.IsExpansion = false; } });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the parent item.
|
||||
/// </summary>
|
||||
/// <value>The parent item.</value>
|
||||
public MindMappingItemEntity ParentItem { get; private set; }
|
||||
/// <summary>
|
||||
/// Gets all childrens maximum show count.
|
||||
/// </summary>
|
||||
/// <value>All childrens maximum show count.</value>
|
||||
public int AllChildrensMaxShowHeight { get { return GetAllChildrensMaxShowHeight(); } }
|
||||
/// <summary>
|
||||
/// Gets the maximum level.
|
||||
/// </summary>
|
||||
/// <value>The maximum level.</value>
|
||||
public int AllChildrensMaxShowWidth { get { return GetAllChildrensMaxShowWidth(); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets all childrens maximum show count.
|
||||
/// </summary>
|
||||
/// <returns>System.Int32.</returns>
|
||||
private int GetAllChildrensMaxShowHeight()
|
||||
{
|
||||
if (!_IsExpansion || _Childrens == null || _Childrens.Length <= 0)
|
||||
return ItemHeight + 10;
|
||||
else
|
||||
{
|
||||
return _Childrens.Sum(p => p == null ? 0 : p.AllChildrensMaxShowHeight);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the maximum level.
|
||||
/// </summary>
|
||||
/// <returns>System.Int32.</returns>
|
||||
private int GetAllChildrensMaxShowWidth()
|
||||
{
|
||||
if (!_IsExpansion || _Childrens == null || _Childrens.Length <= 0)
|
||||
return ItemWidth + 50;
|
||||
else
|
||||
{
|
||||
return ItemWidth + 50 + _Childrens.Max(p => p == null ? 0 : p.AllChildrensMaxShowWidth);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets or sets the working rectangle.
|
||||
/// </summary>
|
||||
/// <value>The working rectangle.</value>
|
||||
internal RectangleF WorkingRectangle { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the draw rectangle.
|
||||
/// </summary>
|
||||
/// <value>The draw rectangle.</value>
|
||||
internal RectangleF DrawRectangle { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the expansion rectangle.
|
||||
/// </summary>
|
||||
/// <value>The expansion rectangle.</value>
|
||||
internal RectangleF ExpansionRectangle { get; set; }
|
||||
/// <summary>
|
||||
/// Gets the height of the item.
|
||||
/// </summary>
|
||||
/// <value>The height of the item.</value>
|
||||
int ItemHeight { get; set; }
|
||||
/// <summary>
|
||||
/// Gets the width of the item.
|
||||
/// </summary>
|
||||
/// <value>The width of the item.</value>
|
||||
int ItemWidth { get; set; }
|
||||
/// <summary>
|
||||
/// Resets the size.
|
||||
/// </summary>
|
||||
private void ResetSize()
|
||||
{
|
||||
string _t = _text;
|
||||
if (string.IsNullOrEmpty(_t))
|
||||
{
|
||||
_t = "aaaa";
|
||||
}
|
||||
Bitmap bit = new Bitmap(1, 1);
|
||||
var g = Graphics.FromImage(bit);
|
||||
var size = g.MeasureString(_t, font);
|
||||
g.Dispose();
|
||||
bit.Dispose();
|
||||
ItemHeight = (int)size.Height;
|
||||
ItemWidth = (int)size.Width;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,423 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : HZH_Controls
|
||||
// Created : 2019-09-11
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="UCMindMapping.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 System.ComponentModel;
|
||||
|
||||
namespace HZH_Controls.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UCMindMapping.
|
||||
/// Implements the <see cref="System.Windows.Forms.UserControl" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Windows.Forms.UserControl" />
|
||||
internal class UCMindMapping : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// The item context menu strip
|
||||
/// </summary>
|
||||
private ContextMenuStrip itemContextMenuStrip;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the item context menu strip.
|
||||
/// </summary>
|
||||
/// <value>The item context menu strip.</value>
|
||||
[Description("节点关联的右键菜单"), Category("自定义")]
|
||||
public ContextMenuStrip ItemContextMenuStrip
|
||||
{
|
||||
get { return itemContextMenuStrip; }
|
||||
set { itemContextMenuStrip = value; }
|
||||
}
|
||||
/// <summary>
|
||||
/// The item backcolor
|
||||
/// </summary>
|
||||
private Color itemBackcolor = Color.FromArgb(255, 77, 59);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the item backcolor.
|
||||
/// </summary>
|
||||
/// <value>The item backcolor.</value>
|
||||
[Description("节点背景色,优先级小于数据源中设置的背景色"), Category("自定义")]
|
||||
public Color ItemBackcolor
|
||||
{
|
||||
get { return itemBackcolor; }
|
||||
set
|
||||
{
|
||||
itemBackcolor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The line color
|
||||
/// </summary>
|
||||
private Color lineColor = Color.Black;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the line.
|
||||
/// </summary>
|
||||
/// <value>The color of the line.</value>
|
||||
[Description("线条颜色"), Category("自定义")]
|
||||
public Color LineColor
|
||||
{
|
||||
get { return lineColor; }
|
||||
set
|
||||
{
|
||||
lineColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The split width
|
||||
/// </summary>
|
||||
private int splitWidth = 50;
|
||||
// private int itemHeight = 20;
|
||||
/// <summary>
|
||||
/// The padding
|
||||
/// </summary>
|
||||
private int padding = 20;
|
||||
|
||||
/// <summary>
|
||||
/// The m rect working
|
||||
/// </summary>
|
||||
Rectangle m_rectWorking = Rectangle.Empty;
|
||||
/// <summary>
|
||||
/// Occurs when [item clicked].
|
||||
/// </summary>
|
||||
public event EventHandler ItemClicked;
|
||||
/// <summary>
|
||||
/// The data source
|
||||
/// </summary>
|
||||
private MindMappingItemEntity dataSource;
|
||||
|
||||
/// <summary>
|
||||
/// The select entity
|
||||
/// </summary>
|
||||
private MindMappingItemEntity selectEntity;
|
||||
/// <summary>
|
||||
/// Gets the select entity.
|
||||
/// </summary>
|
||||
/// <value>The select entity.</value>
|
||||
[Description("选中的数据源"), Category("自定义")]
|
||||
public MindMappingItemEntity SelectEntity
|
||||
{
|
||||
get { return selectEntity; }
|
||||
private set { selectEntity = value; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets or sets the data source.
|
||||
/// </summary>
|
||||
/// <value>The data source.</value>
|
||||
[Description("数据源"), Category("自定义")]
|
||||
public MindMappingItemEntity DataSource
|
||||
{
|
||||
get { return dataSource; }
|
||||
set
|
||||
{
|
||||
dataSource = value;
|
||||
|
||||
ResetSize();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UCMindMapping" /> class.
|
||||
/// </summary>
|
||||
public UCMindMapping()
|
||||
{
|
||||
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.Click += UCMindMapping_Click;
|
||||
this.DoubleClick += UCMindMapping_DoubleClick;
|
||||
this.Load += UCMindMapping_Load;
|
||||
this.MouseClick += UCMindMapping_MouseClick;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Handles the Load event of the UCMindMapping 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 UCMindMapping_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (this.Parent != null)
|
||||
{
|
||||
//父控件大小改变时重置大小和位置
|
||||
this.Parent.SizeChanged += (a, b) =>
|
||||
{
|
||||
ResetSize();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 双击处理,主要用于检测节点双击展开折叠
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
|
||||
void UCMindMapping_DoubleClick(object sender, EventArgs e)
|
||||
{
|
||||
var mouseLocation = this.PointToClient(Control.MousePosition);
|
||||
|
||||
bool bln = CheckDrawRectClick(dataSource, mouseLocation);
|
||||
if (bln)
|
||||
{
|
||||
ResetSize();
|
||||
this.Parent.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 单击处理,主要用于单击节点事件和,展开关闭圆圈处理
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
|
||||
void UCMindMapping_Click(object sender, EventArgs e)
|
||||
{
|
||||
var mouseLocation = this.PointToClient(Control.MousePosition);
|
||||
|
||||
bool bln = CheckExpansionClick(dataSource, mouseLocation);
|
||||
if (bln)
|
||||
{
|
||||
ResetSize();
|
||||
this.Parent.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the MouseClick event of the UCMindMapping control.
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
|
||||
void UCMindMapping_MouseClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (itemContextMenuStrip != null && e.Button == System.Windows.Forms.MouseButtons.Right)
|
||||
{
|
||||
bool bln = CheckDrawRectClick(dataSource, e.Location, false);
|
||||
if (bln)
|
||||
{
|
||||
itemContextMenuStrip.Show(this.PointToScreen(e.Location));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 双击检查
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="mouseLocation">The mouse location.</param>
|
||||
/// <param name="blnDoExpansion">if set to <c>true</c> [BLN do expansion].</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
||||
private bool CheckDrawRectClick(MindMappingItemEntity item, Point mouseLocation, bool blnDoExpansion = true)
|
||||
{
|
||||
if (item == null)
|
||||
return false;
|
||||
else
|
||||
{
|
||||
if (item.DrawRectangle.Contains(mouseLocation))
|
||||
{
|
||||
if (blnDoExpansion)
|
||||
item.IsExpansion = !item.IsExpansion;
|
||||
return true;
|
||||
}
|
||||
if (item.Childrens != null && item.Childrens.Length > 0)
|
||||
{
|
||||
foreach (var child in item.Childrens)
|
||||
{
|
||||
var bln = CheckDrawRectClick(child, mouseLocation, blnDoExpansion);
|
||||
if (bln)
|
||||
return bln;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 单击检查
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="mouseLocation">The mouse location.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
||||
private bool CheckExpansionClick(MindMappingItemEntity item, Point mouseLocation)
|
||||
{
|
||||
if (item == null)
|
||||
return false;
|
||||
else
|
||||
{
|
||||
if (item.DrawRectangle.Contains(mouseLocation))
|
||||
{
|
||||
selectEntity = item;
|
||||
if (ItemClicked != null )
|
||||
{
|
||||
ItemClicked(item, null);
|
||||
}
|
||||
}
|
||||
|
||||
if (item.ExpansionRectangle.Contains(mouseLocation))
|
||||
{
|
||||
item.IsExpansion = !item.IsExpansion;
|
||||
return true;
|
||||
}
|
||||
if (item.Childrens != null && item.Childrens.Length > 0)
|
||||
{
|
||||
foreach (var child in item.Childrens)
|
||||
{
|
||||
var bln = CheckExpansionClick(child, mouseLocation);
|
||||
if (bln)
|
||||
return bln;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
try
|
||||
{
|
||||
base.OnPaint(e);
|
||||
if (m_rectWorking == Rectangle.Empty || m_rectWorking == null)
|
||||
return;
|
||||
var g = e.Graphics;
|
||||
g.SetGDIHigh();
|
||||
|
||||
int intHeight = dataSource.AllChildrensMaxShowHeight;
|
||||
dataSource.WorkingRectangle = new RectangleF(m_rectWorking.Left, m_rectWorking.Top + (m_rectWorking.Height - intHeight) / 2, m_rectWorking.Width, intHeight);
|
||||
|
||||
DrawItem(dataSource, g);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
MessageBox.Show(exc.ToString(), "错误");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 画节点
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="g">The g.</param>
|
||||
private void DrawItem(MindMappingItemEntity item, Graphics g)
|
||||
{
|
||||
//节点
|
||||
var size = g.MeasureString(item.Text, item.Font);
|
||||
item.DrawRectangle = new RectangleF(item.WorkingRectangle.Left + 2, item.WorkingRectangle.Top + (item.WorkingRectangle.Height - size.Height) / 2 + 2, size.Width + 4, size.Height + 4);
|
||||
GraphicsPath drawPath = item.DrawRectangle.CreateRoundedRectanglePath(5);
|
||||
if (item.BackColor.HasValue)
|
||||
g.FillPath(new SolidBrush(item.BackColor.Value), drawPath);
|
||||
else
|
||||
g.FillPath(new SolidBrush(itemBackcolor), drawPath);
|
||||
|
||||
g.DrawString(item.Text, item.Font, new SolidBrush(item.ForeColor), item.DrawRectangle.Location.X + 2, item.DrawRectangle.Location.Y + 2);
|
||||
//子节点
|
||||
if (item.Childrens != null && item.IsExpansion)
|
||||
{
|
||||
for (int i = 0; i < item.Childrens.Length; i++)
|
||||
{
|
||||
var child = item.Childrens[i];
|
||||
if (i == 0)
|
||||
{
|
||||
child.WorkingRectangle = new RectangleF(item.DrawRectangle.Right + splitWidth, item.WorkingRectangle.Top, item.WorkingRectangle.Width - (item.DrawRectangle.Width + splitWidth), child.AllChildrensMaxShowHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
child.WorkingRectangle = new RectangleF(item.DrawRectangle.Right + splitWidth, item.Childrens[i - 1].WorkingRectangle.Bottom, item.WorkingRectangle.Width - (item.DrawRectangle.Width + splitWidth), child.AllChildrensMaxShowHeight);
|
||||
}
|
||||
DrawItem(child, g);
|
||||
}
|
||||
}
|
||||
//连线
|
||||
if (item.ParentItem != null)
|
||||
{
|
||||
g.DrawLines(new Pen(new SolidBrush(lineColor), 1), new PointF[]
|
||||
{
|
||||
new PointF(item.ParentItem.DrawRectangle.Right,item.ParentItem.DrawRectangle.Top+item.ParentItem.DrawRectangle.Height/2),
|
||||
new PointF(item.ParentItem.DrawRectangle.Right+12,item.ParentItem.DrawRectangle.Top+item.ParentItem.DrawRectangle.Height/2),
|
||||
//new PointF(item.ParentItem.DrawRectangle.Right+12,item.DrawRectangle.Top+item.DrawRectangle.Height/2),
|
||||
new PointF(item.DrawRectangle.Left-12,item.DrawRectangle.Top+item.DrawRectangle.Height/2),
|
||||
new PointF(item.DrawRectangle.Left,item.DrawRectangle.Top+item.DrawRectangle.Height/2),
|
||||
});
|
||||
}
|
||||
//展开折叠按钮
|
||||
if (item.Childrens != null && item.Childrens.Length > 0)
|
||||
{
|
||||
RectangleF _rect = new RectangleF(item.DrawRectangle.Right + 1, item.DrawRectangle.Top + (item.DrawRectangle.Height - 10) / 2, 10, 10);
|
||||
item.ExpansionRectangle = _rect;
|
||||
g.FillEllipse(new SolidBrush(this.BackColor), _rect);
|
||||
g.DrawEllipse(new Pen(new SolidBrush(Color.Black)), _rect);
|
||||
g.DrawLine(new Pen(new SolidBrush(lineColor)), _rect.Left + 2, _rect.Y + _rect.Height / 2, _rect.Right - 2, _rect.Y + _rect.Height / 2);
|
||||
if (!item.IsExpansion)
|
||||
{
|
||||
g.DrawLine(new Pen(new SolidBrush(lineColor)), _rect.Left + _rect.Width / 2, _rect.Top + 2, _rect.Left + _rect.Width / 2, _rect.Bottom - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重置大小
|
||||
/// </summary>
|
||||
private void ResetSize()
|
||||
{
|
||||
if (this.Parent == null)
|
||||
return;
|
||||
try
|
||||
{
|
||||
ControlHelper.FreezeControl(this, true);
|
||||
if (dataSource == null)
|
||||
{
|
||||
m_rectWorking = Rectangle.Empty;
|
||||
this.Size = this.Parent.Size;
|
||||
}
|
||||
else
|
||||
{
|
||||
int intWidth = dataSource.AllChildrensMaxShowWidth;
|
||||
int intHeight = dataSource.AllChildrensMaxShowHeight;
|
||||
this.Width = intWidth + padding * 2;
|
||||
this.Height = intHeight + padding * 2;
|
||||
if (this.Width < this.Parent.Width)
|
||||
this.Width = this.Parent.Width;
|
||||
m_rectWorking = new Rectangle(padding, padding, intWidth, intHeight);
|
||||
if (this.Height > this.Parent.Height)
|
||||
{
|
||||
//this.Location = new Point(0, 0);
|
||||
}
|
||||
else
|
||||
this.Location = new Point(0, (this.Parent.Height - this.Height) / 2);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
ControlHelper.FreezeControl(this, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
80
UsingControl/HZHControls/Controls/FactoryControls/MindMapping/UCMindMappingPanel.Designer.cs
generated
Normal file
80
UsingControl/HZHControls/Controls/FactoryControls/MindMapping/UCMindMappingPanel.Designer.cs
generated
Normal file
@@ -0,0 +1,80 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : HZH_Controls
|
||||
// Created : 2019-09-11
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="UCMindMappingPanel.Designer.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.
|
||||
// ***********************************************************************
|
||||
namespace HZH_Controls.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UCMindMappingPanel.
|
||||
/// Implements the <see cref="System.Windows.Forms.UserControl" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Windows.Forms.UserControl" />
|
||||
partial class UCMindMappingPanel
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region 组件设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.ucMindMapping1 = new HZH_Controls.Controls.UCMindMapping();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// ucMindMapping1
|
||||
//
|
||||
this.ucMindMapping1.Location = new System.Drawing.Point(0, 0);
|
||||
this.ucMindMapping1.Name = "ucMindMapping1";
|
||||
this.ucMindMapping1.Size = new System.Drawing.Size(200, 200);
|
||||
this.ucMindMapping1.TabIndex = 0;
|
||||
//
|
||||
// UCMindMappingPanel
|
||||
//
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.AutoScroll = true;
|
||||
this.BackColor = System.Drawing.Color.White;
|
||||
this.Controls.Add(this.ucMindMapping1);
|
||||
this.Name = "UCMindMappingPanel";
|
||||
this.Size = new System.Drawing.Size(200, 200);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// The uc mind mapping1
|
||||
/// </summary>
|
||||
private UCMindMapping ucMindMapping1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : HZH_Controls
|
||||
// Created : 2019-09-11
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="UCMindMappingPanel.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.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace HZH_Controls.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UCMindMappingPanel.
|
||||
/// Implements the <see cref="System.Windows.Forms.UserControl" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Windows.Forms.UserControl" />
|
||||
[DefaultEvent("ItemClicked")]
|
||||
public partial class UCMindMappingPanel : UserControl
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The item context menu strip
|
||||
/// </summary>
|
||||
private ContextMenuStrip itemContextMenuStrip;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the item context menu strip.
|
||||
/// </summary>
|
||||
/// <value>The item context menu strip.</value>
|
||||
[Description("节点关联的右键菜单"), Category("自定义")]
|
||||
public ContextMenuStrip ItemContextMenuStrip
|
||||
{
|
||||
get { return itemContextMenuStrip; }
|
||||
set
|
||||
{
|
||||
itemContextMenuStrip = value;
|
||||
this.ucMindMapping1.ItemContextMenuStrip = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The item backcolor
|
||||
/// </summary>
|
||||
private Color itemBackcolor = Color.FromArgb(255, 77, 59);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the item backcolor.
|
||||
/// </summary>
|
||||
/// <value>The item backcolor.</value>
|
||||
[Description("节点背景色,优先级小于数据源中设置的背景色"), Category("自定义")]
|
||||
public Color ItemBackcolor
|
||||
{
|
||||
get { return itemBackcolor; }
|
||||
set
|
||||
{
|
||||
itemBackcolor = value;
|
||||
this.ucMindMapping1.ItemBackcolor = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The data source
|
||||
/// </summary>
|
||||
private MindMappingItemEntity dataSource;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the data source.
|
||||
/// </summary>
|
||||
/// <value>The data source.</value>
|
||||
[Description("数据源"), Category("自定义")]
|
||||
public MindMappingItemEntity DataSource
|
||||
{
|
||||
get { return dataSource; }
|
||||
set
|
||||
{
|
||||
dataSource = value;
|
||||
this.ucMindMapping1.DataSource = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets or sets the data source.
|
||||
/// </summary>
|
||||
/// <value>The data source.</value>
|
||||
[Description("数据源"), Category("自定义")]
|
||||
public event EventHandler ItemClicked;
|
||||
|
||||
/// <summary>
|
||||
/// The line color
|
||||
/// </summary>
|
||||
private Color lineColor = Color.Black;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the line.
|
||||
/// </summary>
|
||||
/// <value>The color of the line.</value>
|
||||
[Description("线条颜色"), Category("自定义")]
|
||||
public Color LineColor
|
||||
{
|
||||
get { return lineColor; }
|
||||
set
|
||||
{
|
||||
lineColor = value;
|
||||
this.ucMindMapping1.LineColor = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the select entity.
|
||||
/// </summary>
|
||||
/// <value>The select entity.</value>
|
||||
[Description("选中的数据源"), Category("自定义")]
|
||||
public MindMappingItemEntity SelectEntity
|
||||
{
|
||||
get { return ucMindMapping1.SelectEntity; }
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UCMindMappingPanel" /> class.
|
||||
/// </summary>
|
||||
public UCMindMappingPanel()
|
||||
{
|
||||
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);
|
||||
InitializeComponent();
|
||||
ucMindMapping1.ItemClicked += ucMindMapping1_ItemClicked;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the ItemClicked event of the ucMindMapping1 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 ucMindMapping1_ItemClicked(object sender, EventArgs e)
|
||||
{
|
||||
if (ItemClicked != null)
|
||||
{
|
||||
ItemClicked(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
174
UsingControl/HZHControls/Controls/FactoryControls/Pond/UCPond.cs
Normal file
174
UsingControl/HZHControls/Controls/FactoryControls/Pond/UCPond.cs
Normal file
@@ -0,0 +1,174 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : HZH_Controls
|
||||
// Created : 2019-09-06
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="UCPond.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 System.ComponentModel;
|
||||
|
||||
namespace HZH_Controls.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UCPond.
|
||||
/// Implements the <see cref="System.Windows.Forms.UserControl" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Windows.Forms.UserControl" />
|
||||
public class UCPond : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// The maximum value
|
||||
/// </summary>
|
||||
private decimal maxValue = 100;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum value.
|
||||
/// </summary>
|
||||
/// <value>The maximum value.</value>
|
||||
[Description("最大值"), Category("自定义")]
|
||||
public decimal MaxValue
|
||||
{
|
||||
get { return maxValue; }
|
||||
set
|
||||
{
|
||||
if (value < m_value)
|
||||
return;
|
||||
maxValue = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The m value
|
||||
/// </summary>
|
||||
private decimal m_value = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value.
|
||||
/// </summary>
|
||||
/// <value>The value.</value>
|
||||
[Description("值"), Category("自定义")]
|
||||
public decimal Value
|
||||
{
|
||||
get { return m_value; }
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
return;
|
||||
if (value > maxValue)
|
||||
m_value = maxValue;
|
||||
else
|
||||
m_value = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The wall color
|
||||
/// </summary>
|
||||
private Color wallColor = Color.FromArgb(255, 77, 59);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the wall.
|
||||
/// </summary>
|
||||
/// <value>The color of the wall.</value>
|
||||
[Description("池壁颜色"), Category("自定义")]
|
||||
public Color WallColor
|
||||
{
|
||||
get { return wallColor; }
|
||||
set
|
||||
{
|
||||
wallColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The wall width
|
||||
/// </summary>
|
||||
private int wallWidth = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the width of the wall.
|
||||
/// </summary>
|
||||
/// <value>The width of the wall.</value>
|
||||
[Description("池壁宽度"), Category("自定义")]
|
||||
public int WallWidth
|
||||
{
|
||||
get { return wallWidth; }
|
||||
set
|
||||
{
|
||||
if (value <= 0)
|
||||
return;
|
||||
wallWidth = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The liquid color
|
||||
/// </summary>
|
||||
private Color liquidColor = Color.FromArgb(3, 169, 243);
|
||||
|
||||
/// <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; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UCPond" /> class.
|
||||
/// </summary>
|
||||
public UCPond()
|
||||
{
|
||||
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(150, 50);
|
||||
}
|
||||
/// <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);
|
||||
if (Height <= 0)
|
||||
return;
|
||||
var g = e.Graphics;
|
||||
g.SetGDIHigh();
|
||||
int intHeight = (int)(m_value / maxValue * this.Height);
|
||||
if (intHeight != 0)
|
||||
{
|
||||
g.FillRectangle(new SolidBrush(liquidColor), new Rectangle(0, this.Height - intHeight, this.Width, intHeight));
|
||||
}
|
||||
//划边
|
||||
g.FillRectangle(new SolidBrush(wallColor), 0, 0, wallWidth, this.Height);
|
||||
g.FillRectangle(new SolidBrush(wallColor), 0, this.Height - wallWidth, this.Width, wallWidth);
|
||||
g.FillRectangle(new SolidBrush(wallColor), this.Width - wallWidth-1, 0, wallWidth, this.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,475 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : HZH_Controls
|
||||
// Created : 2019-09-10
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="UCThermometer.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 System.ComponentModel;
|
||||
|
||||
namespace HZH_Controls.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UCThermometer.
|
||||
/// Implements the <see cref="System.Windows.Forms.UserControl" />
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Windows.Forms.UserControl" />
|
||||
public class UCThermometer : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// The glass tube color
|
||||
/// </summary>
|
||||
private Color glassTubeColor = Color.FromArgb(211, 211, 211);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the glass tube.
|
||||
/// </summary>
|
||||
/// <value>The color of the glass tube.</value>
|
||||
[Description("玻璃管颜色"), Category("自定义")]
|
||||
public Color GlassTubeColor
|
||||
{
|
||||
get { return glassTubeColor; }
|
||||
set
|
||||
{
|
||||
glassTubeColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The mercury color
|
||||
/// </summary>
|
||||
private Color mercuryColor = Color.FromArgb(255, 77, 59);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the mercury.
|
||||
/// </summary>
|
||||
/// <value>The color of the mercury.</value>
|
||||
[Description("水印颜色"), Category("自定义")]
|
||||
public Color MercuryColor
|
||||
{
|
||||
get { return mercuryColor; }
|
||||
set
|
||||
{
|
||||
mercuryColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The minimum value
|
||||
/// </summary>
|
||||
private decimal minValue = 0;
|
||||
/// <summary>
|
||||
/// 左侧刻度最小值
|
||||
/// </summary>
|
||||
/// <value>The minimum value.</value>
|
||||
[Description("左侧刻度最小值"), Category("自定义")]
|
||||
public decimal MinValue
|
||||
{
|
||||
get { return minValue; }
|
||||
set
|
||||
{
|
||||
minValue = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The maximum value
|
||||
/// </summary>
|
||||
private decimal maxValue = 100;
|
||||
/// <summary>
|
||||
/// 左侧刻度最大值
|
||||
/// </summary>
|
||||
/// <value>The maximum value.</value>
|
||||
[Description("左侧刻度最大值"), Category("自定义")]
|
||||
public decimal MaxValue
|
||||
{
|
||||
get { return maxValue; }
|
||||
set
|
||||
{
|
||||
maxValue = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The m value
|
||||
/// </summary>
|
||||
private decimal m_value = 10;
|
||||
/// <summary>
|
||||
/// 左侧刻度值
|
||||
/// </summary>
|
||||
/// <value>The value.</value>
|
||||
[Description("左侧刻度值"), Category("自定义")]
|
||||
public decimal Value
|
||||
{
|
||||
get { return m_value; }
|
||||
set
|
||||
{
|
||||
m_value = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The split count
|
||||
/// </summary>
|
||||
private int splitCount = 0;
|
||||
/// <summary>
|
||||
/// 刻度分隔份数
|
||||
/// </summary>
|
||||
/// <value>The split count.</value>
|
||||
[Description("刻度分隔份数"), Category("自定义")]
|
||||
public int SplitCount
|
||||
{
|
||||
get { return splitCount; }
|
||||
set
|
||||
{
|
||||
if (value <= 0)
|
||||
return;
|
||||
splitCount = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置控件显示的文字的字体。
|
||||
/// </summary>
|
||||
/// <value>The font.</value>
|
||||
/// <PermissionSet>
|
||||
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||||
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
||||
/// <IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||||
/// </PermissionSet>
|
||||
[Description("获取或设置控件显示的文字的字体"), Category("自定义")]
|
||||
public override Font Font
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Font;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.Font = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置控件的前景色。
|
||||
/// </summary>
|
||||
/// <value>The color of the fore.</value>
|
||||
/// <PermissionSet>
|
||||
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||||
/// </PermissionSet>
|
||||
[Description("获取或设置控件的文字及刻度颜色"), Category("自定义")]
|
||||
public override System.Drawing.Color ForeColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.ForeColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.ForeColor = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The left temperature unit
|
||||
/// </summary>
|
||||
private TemperatureUnit leftTemperatureUnit = TemperatureUnit.C;
|
||||
/// <summary>
|
||||
/// 左侧刻度单位,不可为none
|
||||
/// </summary>
|
||||
/// <value>The left temperature unit.</value>
|
||||
[Description("左侧刻度单位,不可为none"), Category("自定义")]
|
||||
public TemperatureUnit LeftTemperatureUnit
|
||||
{
|
||||
get { return leftTemperatureUnit; }
|
||||
set
|
||||
{
|
||||
if (value == TemperatureUnit.None)
|
||||
return;
|
||||
leftTemperatureUnit = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The right temperature unit
|
||||
/// </summary>
|
||||
private TemperatureUnit rightTemperatureUnit = TemperatureUnit.C;
|
||||
/// <summary>
|
||||
/// 右侧刻度单位,当为none时,不显示
|
||||
/// </summary>
|
||||
/// <value>The right temperature unit.</value>
|
||||
[Description("右侧刻度单位,当为none时,不显示"), Category("自定义")]
|
||||
public TemperatureUnit RightTemperatureUnit
|
||||
{
|
||||
get { return rightTemperatureUnit; }
|
||||
set
|
||||
{
|
||||
rightTemperatureUnit = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The m rect working
|
||||
/// </summary>
|
||||
Rectangle m_rectWorking;
|
||||
/// <summary>
|
||||
/// The m rect left
|
||||
/// </summary>
|
||||
Rectangle m_rectLeft;
|
||||
/// <summary>
|
||||
/// The m rect right
|
||||
/// </summary>
|
||||
Rectangle m_rectRight;
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UCThermometer" /> class.
|
||||
/// </summary>
|
||||
public UCThermometer()
|
||||
{
|
||||
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||
this.SetStyle(ControlStyles.DoubleBuffer, true);
|
||||
this.SetStyle(ControlStyles.ResizeRedraw, true);
|
||||
this.SetStyle(ControlStyles.Selectable, true);
|
||||
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
|
||||
this.SetStyle(ControlStyles.UserPaint, true);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.SizeChanged += UCThermometer_SizeChanged;
|
||||
this.Size = new Size(70, 200);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the SizeChanged event of the UCThermometer 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 UCThermometer_SizeChanged(object sender, EventArgs e)
|
||||
{
|
||||
m_rectWorking = new Rectangle(this.Width / 2 - this.Width / 8, this.Width / 4, this.Width / 4, this.Height - this.Width / 2);
|
||||
m_rectLeft = new Rectangle(0, m_rectWorking.Top + m_rectWorking.Width / 2, (this.Width - this.Width / 4) / 2 - 2, m_rectWorking.Height - m_rectWorking.Width * 2);
|
||||
m_rectRight = new Rectangle(this.Width - (this.Width - this.Width / 4) / 2 + 2, m_rectWorking.Top + m_rectWorking.Width / 2, (this.Width - this.Width / 4) / 2 - 2, m_rectWorking.Height - m_rectWorking.Width * 2);
|
||||
}
|
||||
|
||||
/// <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;
|
||||
g.SetGDIHigh();
|
||||
|
||||
//玻璃管管
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
path.AddLine(m_rectWorking.Left, m_rectWorking.Bottom, m_rectWorking.Left, m_rectWorking.Top + m_rectWorking.Width / 2);
|
||||
path.AddArc(new Rectangle(m_rectWorking.Left, m_rectWorking.Top, m_rectWorking.Width, m_rectWorking.Width), 180, 180);
|
||||
path.AddLine(m_rectWorking.Right, m_rectWorking.Top + m_rectWorking.Width / 2, m_rectWorking.Right, m_rectWorking.Bottom);
|
||||
path.CloseAllFigures();
|
||||
g.FillPath(new SolidBrush(glassTubeColor), path);
|
||||
|
||||
//底部
|
||||
var rectDi = new Rectangle(this.Width / 2 - m_rectWorking.Width, m_rectWorking.Bottom - m_rectWorking.Width - 2, m_rectWorking.Width * 2, m_rectWorking.Width * 2);
|
||||
g.FillEllipse(new SolidBrush(glassTubeColor), rectDi);
|
||||
g.FillEllipse(new SolidBrush(mercuryColor), new Rectangle(rectDi.Left + 4, rectDi.Top + 4, rectDi.Width - 8, rectDi.Height - 8));
|
||||
|
||||
//刻度
|
||||
decimal decSplit = (maxValue - minValue) / splitCount;
|
||||
decimal decSplitHeight = m_rectLeft.Height / splitCount;
|
||||
for (int i = 0; i <= splitCount; i++)
|
||||
{
|
||||
g.DrawLine(new Pen(new SolidBrush(ForeColor), 1), new PointF(m_rectLeft.Left + 2, (float)(m_rectLeft.Bottom - decSplitHeight * i)), new PointF(m_rectLeft.Right, (float)(m_rectLeft.Bottom - decSplitHeight * i)));
|
||||
|
||||
var valueLeft = (minValue + decSplit * i).ToString("0.##");
|
||||
var sizeLeft = g.MeasureString(valueLeft, Font);
|
||||
g.DrawString(valueLeft, Font, new SolidBrush(ForeColor), new PointF(m_rectLeft.Left, m_rectLeft.Bottom - (float)decSplitHeight * i - sizeLeft.Height - 1));
|
||||
|
||||
if (rightTemperatureUnit != TemperatureUnit.None)
|
||||
{
|
||||
g.DrawLine(new Pen(new SolidBrush(Color.Black), 1), new PointF(m_rectRight.Left + 2, (float)(m_rectRight.Bottom - decSplitHeight * i)), new PointF(m_rectRight.Right, (float)(m_rectRight.Bottom - decSplitHeight * i)));
|
||||
var valueRight = GetRightValue(minValue + decSplit * i).ToString("0.##");
|
||||
var sizeRight = g.MeasureString(valueRight, Font);
|
||||
g.DrawString(valueRight, Font, new SolidBrush(ForeColor), new PointF(m_rectRight.Right - sizeRight.Width - 1, m_rectRight.Bottom - (float)decSplitHeight * i - sizeRight.Height - 1));
|
||||
}
|
||||
if (i != splitCount)
|
||||
{
|
||||
if (decSplitHeight > 40)
|
||||
{
|
||||
var decSp1 = decSplitHeight / 10;
|
||||
for (int j = 1; j < 10; j++)
|
||||
{
|
||||
if (j == 5)
|
||||
{
|
||||
g.DrawLine(new Pen(new SolidBrush(ForeColor), 1), new PointF(m_rectLeft.Right - 10, (m_rectLeft.Bottom - (float)decSplitHeight * i - ((float)decSp1 * j))), new PointF(m_rectLeft.Right, (m_rectLeft.Bottom - (float)decSplitHeight * i - ((float)decSp1 * j))));
|
||||
if (rightTemperatureUnit != TemperatureUnit.None)
|
||||
{
|
||||
g.DrawLine(new Pen(new SolidBrush(ForeColor), 1), new PointF(m_rectRight.Left + 10, (m_rectRight.Bottom - (float)decSplitHeight * i - ((float)decSp1 * j))), new PointF(m_rectRight.Left, (m_rectRight.Bottom - (float)decSplitHeight * i - ((float)decSp1 * j))));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g.DrawLine(new Pen(new SolidBrush(ForeColor), 1), new PointF(m_rectLeft.Right - 5, (m_rectLeft.Bottom - (float)decSplitHeight * i - ((float)decSp1 * j))), new PointF(m_rectLeft.Right, (m_rectLeft.Bottom - (float)decSplitHeight * i - ((float)decSp1 * j))));
|
||||
if (rightTemperatureUnit != TemperatureUnit.None)
|
||||
{
|
||||
g.DrawLine(new Pen(new SolidBrush(ForeColor), 1), new PointF(m_rectRight.Left + 5, (m_rectRight.Bottom - (float)decSplitHeight * i - ((float)decSp1 * j))), new PointF(m_rectRight.Left, (m_rectRight.Bottom - (float)decSplitHeight * i - ((float)decSp1 * j))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (decSplitHeight > 10)
|
||||
{
|
||||
g.DrawLine(new Pen(new SolidBrush(ForeColor), 1), new PointF(m_rectLeft.Right - 5, (m_rectLeft.Bottom - (float)decSplitHeight * i - (float)decSplitHeight / 2)), new PointF(m_rectLeft.Right, (m_rectLeft.Bottom - (float)decSplitHeight * i - (float)decSplitHeight / 2)));
|
||||
if (rightTemperatureUnit != TemperatureUnit.None)
|
||||
{
|
||||
g.DrawLine(new Pen(new SolidBrush(ForeColor), 1), new PointF(m_rectRight.Left + 5, (m_rectRight.Bottom - (float)decSplitHeight * i - (float)decSplitHeight / 2)), new PointF(m_rectRight.Left, (m_rectRight.Bottom - (float)decSplitHeight * i - (float)decSplitHeight / 2)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//单位
|
||||
string strLeftUnit = GetUnitChar(leftTemperatureUnit);
|
||||
g.DrawString(strLeftUnit, Font, new SolidBrush(ForeColor), new PointF(m_rectLeft.Left + 2, 2));
|
||||
if (rightTemperatureUnit != TemperatureUnit.None)
|
||||
{
|
||||
string strRightUnit = GetUnitChar(rightTemperatureUnit);
|
||||
var rightSize = g.MeasureString(strRightUnit, Font);
|
||||
g.DrawString(strRightUnit, Font, new SolidBrush(ForeColor), new PointF(m_rectRight.Right - 2 - rightSize.Width, 2));
|
||||
}
|
||||
//值
|
||||
float fltHeightValue = (float)(Value / (maxValue - minValue) * m_rectLeft.Height);
|
||||
RectangleF rectValue = new RectangleF(m_rectWorking.Left + 4, m_rectLeft.Top + (m_rectLeft.Height - fltHeightValue), m_rectWorking.Width - 8, fltHeightValue + (m_rectWorking.Height - m_rectWorking.Width / 2 - m_rectLeft.Height));
|
||||
g.FillRectangle(new SolidBrush(mercuryColor), rectValue);
|
||||
|
||||
|
||||
var sizeValue = g.MeasureString(m_value.ToString("0.##"), Font);
|
||||
g.DrawString(m_value.ToString("0.##"), Font, new SolidBrush(Color.White), new PointF(rectDi.Left + (rectDi.Width - sizeValue.Width) / 2, rectDi.Top + (rectDi.Height - sizeValue.Height) / 2 + 1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unit character.
|
||||
/// </summary>
|
||||
/// <param name="unit">The unit.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
private string GetUnitChar(TemperatureUnit unit)
|
||||
{
|
||||
string strUnit = "℃";
|
||||
switch (unit)
|
||||
{
|
||||
case TemperatureUnit.C:
|
||||
strUnit = "℃";
|
||||
break;
|
||||
case TemperatureUnit.F:
|
||||
strUnit = "℉";
|
||||
break;
|
||||
case TemperatureUnit.K:
|
||||
strUnit = "K";
|
||||
break;
|
||||
case TemperatureUnit.R:
|
||||
strUnit = "°R";
|
||||
break;
|
||||
case TemperatureUnit.Re:
|
||||
strUnit = "°Re";
|
||||
break;
|
||||
}
|
||||
return strUnit;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the right value.
|
||||
/// </summary>
|
||||
/// <param name="decValue">The decimal value.</param>
|
||||
/// <returns>System.Decimal.</returns>
|
||||
private decimal GetRightValue(decimal decValue)
|
||||
{
|
||||
//先将左侧的换算为摄氏度
|
||||
var dec = decValue;
|
||||
switch (leftTemperatureUnit)
|
||||
{
|
||||
case TemperatureUnit.F:
|
||||
dec = (decValue - 32) / (9M / 5M);
|
||||
break;
|
||||
case TemperatureUnit.K:
|
||||
dec = decValue - 273;
|
||||
break;
|
||||
case TemperatureUnit.R:
|
||||
dec = decValue / (5M / 9M) - 273.15M;
|
||||
break;
|
||||
case TemperatureUnit.Re:
|
||||
dec = decValue / 1.25M;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (rightTemperatureUnit)
|
||||
{
|
||||
case TemperatureUnit.C:
|
||||
return dec;
|
||||
case TemperatureUnit.F:
|
||||
return 9M / 5M * dec + 32;
|
||||
case TemperatureUnit.K:
|
||||
return dec + 273;
|
||||
case TemperatureUnit.R:
|
||||
return (dec + 273.15M) * (5M / 9M);
|
||||
case TemperatureUnit.Re:
|
||||
return dec * 1.25M;
|
||||
}
|
||||
return decValue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enum TemperatureUnit
|
||||
/// </summary>
|
||||
public enum TemperatureUnit
|
||||
{
|
||||
/// <summary>
|
||||
/// 不显示
|
||||
/// </summary>
|
||||
None,
|
||||
/// <summary>
|
||||
/// 摄氏度
|
||||
/// </summary>
|
||||
C,
|
||||
/// <summary>
|
||||
/// 华氏度
|
||||
/// </summary>
|
||||
F,
|
||||
/// <summary>
|
||||
/// 开氏度
|
||||
/// </summary>
|
||||
K,
|
||||
/// <summary>
|
||||
/// 兰氏度
|
||||
/// </summary>
|
||||
R,
|
||||
/// <summary>
|
||||
/// 列氏度
|
||||
/// </summary>
|
||||
Re
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,449 @@
|
||||
// ***********************************************************************
|
||||
// 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;
|
||||
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>
|
||||
/// Occurs when [open checked].
|
||||
/// </summary>
|
||||
[Description("打开状态改变事件"), Category("自定义")]
|
||||
public event EventHandler OpenChecked;
|
||||
/// <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(255, 77, 59);
|
||||
|
||||
/// <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(232, 30, 99);
|
||||
|
||||
/// <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(3, 169, 243);
|
||||
|
||||
/// <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(3, 169, 243);
|
||||
|
||||
/// <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();
|
||||
if (OpenChecked != null)
|
||||
{
|
||||
OpenChecked(this, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <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 == LiquidDirection.None)
|
||||
m_timer.Enabled = false;
|
||||
else
|
||||
m_timer.Enabled = true;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The liquid speed
|
||||
/// </summary>
|
||||
private int liquidSpeed = 100;
|
||||
|
||||
/// <summary>
|
||||
/// 液体流速,越小,速度越快Gets or sets the liquid speed.
|
||||
/// </summary>
|
||||
/// <value>The liquid speed.</value>
|
||||
[Description("液体流速,越小,速度越快"), Category("自定义")]
|
||||
public int LiquidSpeed
|
||||
{
|
||||
get { return liquidSpeed; }
|
||||
set
|
||||
{
|
||||
if (value <= 0)
|
||||
return;
|
||||
liquidSpeed = value;
|
||||
m_timer.Interval = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The liquid color
|
||||
/// </summary>
|
||||
private Color liquidColor = Color.FromArgb(3, 169, 243);
|
||||
|
||||
/// <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 != LiquidDirection.None)
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The m timer
|
||||
/// </summary>
|
||||
Timer m_timer;
|
||||
/// <summary>
|
||||
/// The int line left
|
||||
/// </summary>
|
||||
int intLineLeft = 0;
|
||||
|
||||
/// <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(120, 100);
|
||||
m_timer = new Timer();
|
||||
m_timer.Interval = 100;
|
||||
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 += 2;
|
||||
if (intLineLeft > 12)
|
||||
intLineLeft = 0;
|
||||
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(0, this.Height / 2, this.Width, this.Height / 2 - this.Height / 8);
|
||||
rectJK1 = new Rectangle(this.Height / 8, rectGuan.Top - this.Height / 8, rectGuan.Height / 2, rectGuan.Height + this.Height / 4);
|
||||
rectJK2 = new Rectangle(rectGuan.Right - this.Height / 8 - rectGuan.Height / 2, rectGuan.Top - this.Height / 8, rectGuan.Height / 2, rectGuan.Height + this.Height / 4);
|
||||
linePath.AddLine(new Point(rectGuan.Left - 10, rectGuan.Top + rectGuan.Height / 2), new Point(rectGuan.Right + 10, rectGuan.Top + rectGuan.Height / 2));
|
||||
rectZ = new Rectangle(rectGuan.Left + (rectGuan.Width - rectGuan.Height / 4) / 2, 10, rectGuan.Height / 4, rectGuan.Top - 10);
|
||||
Point[] psTop = new Point[]
|
||||
{
|
||||
new Point(rectGuan.Left+(rectGuan.Width-rectGuan.Height/2)/2,rectGuan.Top- this.Height / 8- 5 ),
|
||||
new Point(rectGuan.Right-(rectGuan.Width-rectGuan.Height/2)/2,rectGuan.Top- this.Height / 8- 5 ),
|
||||
new Point(rectGuan.Right-(rectGuan.Width-rectGuan.Height)/2,rectGuan.Top+2 ),
|
||||
new Point(rectGuan.Left+(rectGuan.Width-rectGuan.Height)/2,rectGuan.Top +2),
|
||||
};
|
||||
dzPath.AddLines(psTop);
|
||||
dzPath.CloseAllFigures();
|
||||
if (opened)
|
||||
{
|
||||
bsPath.AddLine(rectGuan.Left + (rectGuan.Width - rectGuan.Height - 10) / 2, 10 + (rectGuan.Height / 3) / 2, rectGuan.Left + (rectGuan.Width - rectGuan.Height - 10) / 2 + rectGuan.Height + 10, 10 + (rectGuan.Height / 3) / 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
bsPath.AddLine(new Point(rectGuan.Left + rectGuan.Width / 2 - 3, 1), new Point(rectGuan.Left + rectGuan.Width / 2 + 4, rectGuan.Height + 10));
|
||||
}
|
||||
break;
|
||||
case ValveStyle.Horizontal_Bottom:
|
||||
rectGuan = new Rectangle(0, this.Height / 8, this.Width, this.Height / 2 - this.Height / 8);
|
||||
rectJK1 = new Rectangle(this.Height / 8, rectGuan.Top - this.Height / 8, rectGuan.Height / 2, rectGuan.Height + this.Height / 4);
|
||||
rectJK2 = new Rectangle(rectGuan.Right - this.Height / 8 - rectGuan.Height / 2, rectGuan.Top - this.Height / 8, rectGuan.Height / 2, rectGuan.Height + this.Height / 4);
|
||||
linePath.AddLine(new Point(rectGuan.Left - 10, rectGuan.Top + rectGuan.Height / 2), new Point(rectGuan.Right + 10, rectGuan.Top + rectGuan.Height / 2));
|
||||
rectZ = new Rectangle(rectGuan.Left + (rectGuan.Width - rectGuan.Height / 4) / 2, rectGuan.Bottom + 10, rectGuan.Height / 4, this.Height - 10 - (rectGuan.Bottom + 10));
|
||||
Point[] psBottom = new Point[]
|
||||
{
|
||||
new Point(rectGuan.Left+(rectGuan.Width-rectGuan.Height/2)/2,rectGuan.Bottom+ this.Height / 8+ 5 ),
|
||||
new Point(rectGuan.Right-(rectGuan.Width-rectGuan.Height/2)/2,rectGuan.Bottom+ this.Height / 8+ 5 ),
|
||||
new Point(rectGuan.Right-(rectGuan.Width-rectGuan.Height)/2,rectGuan.Bottom-2 ),
|
||||
new Point(rectGuan.Left+(rectGuan.Width-rectGuan.Height)/2,rectGuan.Bottom-2),
|
||||
};
|
||||
dzPath.AddLines(psBottom);
|
||||
dzPath.CloseAllFigures();
|
||||
if (opened)
|
||||
{
|
||||
bsPath.AddLine(rectGuan.Left + (rectGuan.Width - rectGuan.Height - 10) / 2, this.Height - (10 + (rectGuan.Height / 3) / 2), rectGuan.Left + (rectGuan.Width - rectGuan.Height - 10) / 2 + rectGuan.Height + 10, this.Height - (10 + (rectGuan.Height / 3) / 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
bsPath.AddLine(new Point(rectGuan.Left + rectGuan.Width / 2 - 3, this.Height - 1), new Point(rectGuan.Left + rectGuan.Width / 2 + 4, this.Height - (rectGuan.Height + 10)));
|
||||
}
|
||||
break;
|
||||
case ValveStyle.Vertical_Left:
|
||||
rectGuan = new Rectangle(this.Width / 8, 0, this.Width / 2 - this.Width / 8, this.Height);
|
||||
rectJK1 = new Rectangle(0, this.Width / 8, rectGuan.Width + this.Width / 4, rectGuan.Width / 2);
|
||||
rectJK2 = new Rectangle(0, this.Height - this.Width / 8 - rectGuan.Width / 2, rectGuan.Width + this.Width / 4, rectGuan.Width / 2);
|
||||
linePath.AddLine(new Point(rectGuan.Left + rectGuan.Width / 2, rectGuan.Top - 10), new Point(rectGuan.Left + rectGuan.Width / 2, rectGuan.Bottom + 10));
|
||||
rectZ = new Rectangle(rectGuan.Right, rectGuan.Top + (rectGuan.Height - rectGuan.Width / 4) / 2, rectGuan.Right - 10, rectGuan.Width / 4);
|
||||
Point[] psLeft = new Point[]
|
||||
{
|
||||
new Point(rectGuan.Right+ this.Width / 8+ 5 ,rectGuan.Top + (rectGuan.Height - rectGuan.Width / 2) / 2),
|
||||
new Point(rectGuan.Right+ this.Width / 8+ 5 ,rectGuan.Top + (rectGuan.Height - rectGuan.Width / 2) / 2+rectGuan.Width / 2),
|
||||
new Point(rectGuan.Right-2, rectGuan.Top +(rectGuan.Height-rectGuan.Width)/2+rectGuan.Width),
|
||||
new Point(rectGuan.Right-2, rectGuan.Top +(rectGuan.Height-rectGuan.Width)/2),
|
||||
};
|
||||
dzPath.AddLines(psLeft);
|
||||
dzPath.CloseAllFigures();
|
||||
if (opened)
|
||||
{
|
||||
bsPath.AddLine(this.Width - (10 + (rectGuan.Width / 3) / 2), rectGuan.Top + (rectGuan.Height - rectGuan.Width - 10) / 2, this.Width - (10 + (rectGuan.Width / 3) / 2), rectGuan.Top + (rectGuan.Height - rectGuan.Width - 10) / 2 + rectGuan.Width + 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
bsPath.AddLine(new Point(this.Width - 1, rectGuan.Top + rectGuan.Height / 2 - 3), new Point(this.Width - (rectGuan.Width + 10), rectGuan.Top + rectGuan.Height / 2 + 4));
|
||||
}
|
||||
break;
|
||||
case ValveStyle.Vertical_Right:
|
||||
rectGuan = new Rectangle(this.Width - this.Width / 8 - (this.Width / 2 - this.Width / 8), 0, this.Width / 2 - this.Width / 8, this.Height);
|
||||
rectJK1 = new Rectangle(this.Width - (rectGuan.Width + this.Width / 4), this.Width / 8, rectGuan.Width + this.Width / 4, rectGuan.Width / 2);
|
||||
rectJK2 = new Rectangle(this.Width - (rectGuan.Width + this.Width / 4), this.Height - this.Width / 8 - rectGuan.Width / 2, rectGuan.Width + this.Width / 4, rectGuan.Width / 2);
|
||||
linePath.AddLine(new Point(rectGuan.Left + rectGuan.Width / 2, rectGuan.Top - 10), new Point(rectGuan.Left + rectGuan.Width / 2, rectGuan.Bottom + 10));
|
||||
rectZ = new Rectangle(10, rectGuan.Top + (rectGuan.Height - rectGuan.Width / 4) / 2, rectGuan.Left - 10, rectGuan.Width / 4);
|
||||
Point[] psRight = new Point[]
|
||||
{
|
||||
new Point(rectGuan.Left- (this.Width / 8+ 5) ,rectGuan.Top + (rectGuan.Height - rectGuan.Width / 2) / 2),
|
||||
new Point(rectGuan.Left-( this.Width / 8+ 5) ,rectGuan.Top + (rectGuan.Height - rectGuan.Width / 2) / 2+rectGuan.Width / 2),
|
||||
new Point(rectGuan.Left+2, rectGuan.Top +(rectGuan.Height-rectGuan.Width)/2+rectGuan.Width),
|
||||
new Point(rectGuan.Left+2, rectGuan.Top +(rectGuan.Height-rectGuan.Width)/2),
|
||||
};
|
||||
dzPath.AddLines(psRight);
|
||||
dzPath.CloseAllFigures();
|
||||
|
||||
if (opened)
|
||||
{
|
||||
bsPath.AddLine((10 + (rectGuan.Width / 3) / 2), rectGuan.Top + (rectGuan.Height - rectGuan.Width - 10) / 2, (10 + (rectGuan.Width / 3) / 2), rectGuan.Top + (rectGuan.Height - rectGuan.Width - 10) / 2 + rectGuan.Width + 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
bsPath.AddLine(new Point(1, rectGuan.Top + rectGuan.Height / 2 - 3), new Point((rectGuan.Width + 10), rectGuan.Top + rectGuan.Height / 2 + 4));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//管道
|
||||
g.FillRectangle(new SolidBrush(valveColor), rectGuan);
|
||||
//接口
|
||||
g.FillRectangle(new SolidBrush(valveColor), rectJK1);
|
||||
g.FillRectangle(new SolidBrush(Color.FromArgb(40, Color.White)), rectJK1);
|
||||
g.FillRectangle(new SolidBrush(valveColor), rectJK2);
|
||||
g.FillRectangle(new SolidBrush(Color.FromArgb(40, Color.White)), rectJK2);
|
||||
|
||||
|
||||
//高亮
|
||||
int intCount = (valveStyle.ToString().StartsWith("H") ? rectGuan.Height : rectGuan.Width) / 2 / 4;
|
||||
for (int i = 0; i < intCount; i++)
|
||||
{
|
||||
int _penWidth = (valveStyle.ToString().StartsWith("H") ? rectGuan.Height : rectGuan.Width) / 2 - 4 * i;
|
||||
if (_penWidth <= 0)
|
||||
_penWidth = 1;
|
||||
g.DrawPath(new Pen(new SolidBrush(Color.FromArgb(40, Color.White.R, Color.White.G, Color.White.B)), _penWidth), linePath);
|
||||
if (_penWidth == 1)
|
||||
break;
|
||||
}
|
||||
|
||||
g.SetGDIHigh();
|
||||
//轴
|
||||
g.FillRectangle(new SolidBrush(axisColor), rectZ);
|
||||
|
||||
//阀门底座
|
||||
g.FillPath(new SolidBrush(asisBottomColor), dzPath);
|
||||
g.FillPath(new SolidBrush(Color.FromArgb(50, Color.White)), dzPath);
|
||||
|
||||
//把手
|
||||
g.DrawPath(new Pen(new SolidBrush(switchColor), (valveStyle.ToString().StartsWith("H") ? rectGuan.Height : rectGuan.Width) / 3), bsPath);
|
||||
|
||||
//液体流动
|
||||
if (opened)
|
||||
{
|
||||
Pen p = new Pen(new SolidBrush(liquidColor), 4);
|
||||
p.DashPattern = new float[] { 6, 6 };
|
||||
p.DashOffset = intLineLeft * (LiquidDirection == LiquidDirection.Forward ? -1 : 1);
|
||||
g.DrawPath(p, linePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enum ValveStyle
|
||||
/// </summary>
|
||||
public enum ValveStyle
|
||||
{
|
||||
/// <summary>
|
||||
/// 横向,开关在上方
|
||||
/// </summary>
|
||||
Horizontal_Top,
|
||||
/// <summary>
|
||||
/// 横向,开关在下方
|
||||
/// </summary>
|
||||
Horizontal_Bottom,
|
||||
/// <summary>
|
||||
/// 纵向,开关在左侧
|
||||
/// </summary>
|
||||
Vertical_Left,
|
||||
/// <summary>
|
||||
/// 纵向,开关在右侧
|
||||
/// </summary>
|
||||
Vertical_Right,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user