Commit ee2edcf0 HZH

信号灯

1 个父辈 dd2fa95b
// ***********************************************************************
// 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.FactoryControls.Lamp
{
/// <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), this.ClientRectangle);
if (isHighlight)
{
GraphicsPath gp = new GraphicsPath();
Rectangle rec = new Rectangle(5, 5, this.Width - 10, this.Height - 10);
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 - 8, this.Height - 8));
}
}
}
}
...@@ -103,6 +103,9 @@ ...@@ -103,6 +103,9 @@
<Compile Include="Controls\FactoryControls\Conveyor\UCConveyor.cs"> <Compile Include="Controls\FactoryControls\Conveyor\UCConveyor.cs">
<SubType>UserControl</SubType> <SubType>UserControl</SubType>
</Compile> </Compile>
<Compile Include="Controls\FactoryControls\Lamp\UCSignalLamp.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\FactoryControls\Pond\UCPond.cs"> <Compile Include="Controls\FactoryControls\Pond\UCPond.cs">
<SubType>UserControl</SubType> <SubType>UserControl</SubType>
</Compile> </Compile>
......
...@@ -28,6 +28,12 @@ ...@@ -28,6 +28,12 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.ucSignalLamp1 = new HZH_Controls.Controls.FactoryControls.Lamp.UCSignalLamp();
this.ucBlower6 = new HZH_Controls.Controls.UCBlower();
this.ucBlower5 = new HZH_Controls.Controls.UCBlower();
this.ucBlower4 = new HZH_Controls.Controls.UCBlower();
this.ucBlower3 = new HZH_Controls.Controls.UCBlower();
this.ucBlower2 = new HZH_Controls.Controls.UCBlower();
this.ucBlower1 = new HZH_Controls.Controls.UCBlower(); this.ucBlower1 = new HZH_Controls.Controls.UCBlower();
this.ucValve2 = new HZH_Controls.Controls.UCValve(); this.ucValve2 = new HZH_Controls.Controls.UCValve();
this.ucPond1 = new HZH_Controls.Controls.UCPond(); this.ucPond1 = new HZH_Controls.Controls.UCPond();
...@@ -70,13 +76,76 @@ ...@@ -70,13 +76,76 @@
this.ucConduit10 = new HZH_Controls.Controls.Conduit.UCConduit(); this.ucConduit10 = new HZH_Controls.Controls.Conduit.UCConduit();
this.ucConduit1 = new HZH_Controls.Controls.Conduit.UCConduit(); this.ucConduit1 = new HZH_Controls.Controls.Conduit.UCConduit();
this.ucBottle1 = new HZH_Controls.Controls.UCBottle(); this.ucBottle1 = new HZH_Controls.Controls.UCBottle();
this.ucBlower2 = new HZH_Controls.Controls.UCBlower();
this.ucBlower3 = new HZH_Controls.Controls.UCBlower();
this.ucBlower4 = new HZH_Controls.Controls.UCBlower();
this.ucBlower5 = new HZH_Controls.Controls.UCBlower();
this.ucBlower6 = new HZH_Controls.Controls.UCBlower();
this.SuspendLayout(); this.SuspendLayout();
// //
// ucSignalLamp1
//
this.ucSignalLamp1.IsHighlight = true;
this.ucSignalLamp1.IsShowBorder = true;
this.ucSignalLamp1.LampColor = new System.Drawing.Color[] {
System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59))))),
System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))))};
this.ucSignalLamp1.Location = new System.Drawing.Point(314, 104);
this.ucSignalLamp1.Name = "ucSignalLamp1";
this.ucSignalLamp1.Size = new System.Drawing.Size(74, 74);
this.ucSignalLamp1.TabIndex = 25;
this.ucSignalLamp1.TwinkleSpeed = 300;
//
// ucBlower6
//
this.ucBlower6.BlowerColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucBlower6.EntranceDirection = HZH_Controls.Controls.BlowerEntranceDirection.Up;
this.ucBlower6.ExitDirection = HZH_Controls.Controls.BlowerExitDirection.Up;
this.ucBlower6.FanColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243)))));
this.ucBlower6.Location = new System.Drawing.Point(1085, 366);
this.ucBlower6.Name = "ucBlower6";
this.ucBlower6.Size = new System.Drawing.Size(78, 89);
this.ucBlower6.TabIndex = 24;
//
// ucBlower5
//
this.ucBlower5.BlowerColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucBlower5.EntranceDirection = HZH_Controls.Controls.BlowerEntranceDirection.Right;
this.ucBlower5.ExitDirection = HZH_Controls.Controls.BlowerExitDirection.Right;
this.ucBlower5.FanColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243)))));
this.ucBlower5.Location = new System.Drawing.Point(1001, 366);
this.ucBlower5.Name = "ucBlower5";
this.ucBlower5.Size = new System.Drawing.Size(78, 89);
this.ucBlower5.TabIndex = 24;
//
// ucBlower4
//
this.ucBlower4.BlowerColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucBlower4.EntranceDirection = HZH_Controls.Controls.BlowerEntranceDirection.Right;
this.ucBlower4.ExitDirection = HZH_Controls.Controls.BlowerExitDirection.Left;
this.ucBlower4.FanColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243)))));
this.ucBlower4.Location = new System.Drawing.Point(918, 366);
this.ucBlower4.Name = "ucBlower4";
this.ucBlower4.Size = new System.Drawing.Size(78, 89);
this.ucBlower4.TabIndex = 24;
//
// ucBlower3
//
this.ucBlower3.BlowerColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucBlower3.EntranceDirection = HZH_Controls.Controls.BlowerEntranceDirection.Left;
this.ucBlower3.ExitDirection = HZH_Controls.Controls.BlowerExitDirection.Up;
this.ucBlower3.FanColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243)))));
this.ucBlower3.Location = new System.Drawing.Point(834, 366);
this.ucBlower3.Name = "ucBlower3";
this.ucBlower3.Size = new System.Drawing.Size(78, 89);
this.ucBlower3.TabIndex = 24;
//
// ucBlower2
//
this.ucBlower2.BlowerColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucBlower2.EntranceDirection = HZH_Controls.Controls.BlowerEntranceDirection.Left;
this.ucBlower2.ExitDirection = HZH_Controls.Controls.BlowerExitDirection.Right;
this.ucBlower2.FanColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243)))));
this.ucBlower2.Location = new System.Drawing.Point(741, 367);
this.ucBlower2.Name = "ucBlower2";
this.ucBlower2.Size = new System.Drawing.Size(78, 89);
this.ucBlower2.TabIndex = 24;
//
// ucBlower1 // ucBlower1
// //
this.ucBlower1.BlowerColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59))))); this.ucBlower1.BlowerColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
...@@ -649,66 +718,12 @@ ...@@ -649,66 +718,12 @@
0, 0,
0}); 0});
// //
// ucBlower2
//
this.ucBlower2.BlowerColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucBlower2.EntranceDirection = HZH_Controls.Controls.BlowerEntranceDirection.Left;
this.ucBlower2.ExitDirection = HZH_Controls.Controls.BlowerExitDirection.Right;
this.ucBlower2.FanColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243)))));
this.ucBlower2.Location = new System.Drawing.Point(741, 367);
this.ucBlower2.Name = "ucBlower2";
this.ucBlower2.Size = new System.Drawing.Size(78, 89);
this.ucBlower2.TabIndex = 24;
//
// ucBlower3
//
this.ucBlower3.BlowerColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucBlower3.EntranceDirection = HZH_Controls.Controls.BlowerEntranceDirection.Left;
this.ucBlower3.ExitDirection = HZH_Controls.Controls.BlowerExitDirection.Up;
this.ucBlower3.FanColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243)))));
this.ucBlower3.Location = new System.Drawing.Point(834, 366);
this.ucBlower3.Name = "ucBlower3";
this.ucBlower3.Size = new System.Drawing.Size(78, 89);
this.ucBlower3.TabIndex = 24;
//
// ucBlower4
//
this.ucBlower4.BlowerColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucBlower4.EntranceDirection = HZH_Controls.Controls.BlowerEntranceDirection.Right;
this.ucBlower4.ExitDirection = HZH_Controls.Controls.BlowerExitDirection.Left;
this.ucBlower4.FanColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243)))));
this.ucBlower4.Location = new System.Drawing.Point(918, 366);
this.ucBlower4.Name = "ucBlower4";
this.ucBlower4.Size = new System.Drawing.Size(78, 89);
this.ucBlower4.TabIndex = 24;
//
// ucBlower5
//
this.ucBlower5.BlowerColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucBlower5.EntranceDirection = HZH_Controls.Controls.BlowerEntranceDirection.Right;
this.ucBlower5.ExitDirection = HZH_Controls.Controls.BlowerExitDirection.Right;
this.ucBlower5.FanColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243)))));
this.ucBlower5.Location = new System.Drawing.Point(1001, 366);
this.ucBlower5.Name = "ucBlower5";
this.ucBlower5.Size = new System.Drawing.Size(78, 89);
this.ucBlower5.TabIndex = 24;
//
// ucBlower6
//
this.ucBlower6.BlowerColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucBlower6.EntranceDirection = HZH_Controls.Controls.BlowerEntranceDirection.Up;
this.ucBlower6.ExitDirection = HZH_Controls.Controls.BlowerExitDirection.Up;
this.ucBlower6.FanColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243)))));
this.ucBlower6.Location = new System.Drawing.Point(1085, 366);
this.ucBlower6.Name = "ucBlower6";
this.ucBlower6.Size = new System.Drawing.Size(78, 89);
this.ucBlower6.TabIndex = 24;
//
// Form4 // Form4
// //
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.BackColor = System.Drawing.Color.White; this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(1368, 680); this.ClientSize = new System.Drawing.Size(1368, 680);
this.Controls.Add(this.ucSignalLamp1);
this.Controls.Add(this.ucBlower6); this.Controls.Add(this.ucBlower6);
this.Controls.Add(this.ucBlower5); this.Controls.Add(this.ucBlower5);
this.Controls.Add(this.ucBlower4); this.Controls.Add(this.ucBlower4);
...@@ -811,5 +826,6 @@ ...@@ -811,5 +826,6 @@
private HZH_Controls.Controls.UCBlower ucBlower4; private HZH_Controls.Controls.UCBlower ucBlower4;
private HZH_Controls.Controls.UCBlower ucBlower5; private HZH_Controls.Controls.UCBlower ucBlower5;
private HZH_Controls.Controls.UCBlower ucBlower6; private HZH_Controls.Controls.UCBlower ucBlower6;
private HZH_Controls.Controls.FactoryControls.Lamp.UCSignalLamp ucSignalLamp1;
} }
} }
\ No newline at end of file \ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!