Commit a264694e HZH

传送带

1 个父辈 389b3670
// ***********************************************************************
// 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();
path.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, (inclination >= 0 ? (m_workingRect.Top) : (m_workingRect.Bottom - conveyorHeight)), conveyorHeight, conveyorHeight), 270 - (float)inclination, 180F);
path.CloseAllFigures();
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
}
}
......@@ -42,7 +42,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Controls\Bottle\UCBottle.cs">
<Compile Include="Controls\FactoryControls\Bottle\UCBottle.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\BtnsGroup\UCBtnsGroup.cs">
......@@ -69,7 +69,7 @@
<Compile Include="Controls\ComboBox\UCComboxGridPanel.Designer.cs">
<DependentUpon>UCComboxGridPanel.cs</DependentUpon>
</Compile>
<Compile Include="Controls\Conduit\UCConduit.cs">
<Compile Include="Controls\FactoryControls\Conduit\UCConduit.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\DataGridView\DataGridViewCellEntity.cs" />
......@@ -96,6 +96,9 @@
<Compile Include="Controls\DataGridView\UCDataGridViewTreeRow.Designer.cs">
<DependentUpon>UCDataGridViewTreeRow.cs</DependentUpon>
</Compile>
<Compile Include="Controls\FactoryControls\Conveyor\UCConveyor.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\LED\UCLEDDataTime.cs">
<SubType>UserControl</SubType>
</Compile>
......
......@@ -28,7 +28,10 @@
/// </summary>
private void InitializeComponent()
{
this.ucBottle1 = new HZH_Controls.Controls.UCBottle();
this.ucConveyor2 = new HZH_Controls.Controls.UCConveyor();
this.ucConveyor4 = new HZH_Controls.Controls.UCConveyor();
this.ucConveyor3 = new HZH_Controls.Controls.UCConveyor();
this.ucConveyor1 = new HZH_Controls.Controls.UCConveyor();
this.ucConduit9 = new HZH_Controls.Controls.Conduit.UCConduit();
this.ucConduit22 = new HZH_Controls.Controls.Conduit.UCConduit();
this.ucConduit24 = new HZH_Controls.Controls.Conduit.UCConduit();
......@@ -54,29 +57,63 @@
this.ucConduit11 = new HZH_Controls.Controls.Conduit.UCConduit();
this.ucConduit10 = new HZH_Controls.Controls.Conduit.UCConduit();
this.ucConduit1 = new HZH_Controls.Controls.Conduit.UCConduit();
this.ucBottle2 = new HZH_Controls.Controls.UCBottle();
this.ucBottle1 = new HZH_Controls.Controls.UCBottle();
this.ucConveyor5 = new HZH_Controls.Controls.UCConveyor();
this.ucConveyor6 = new HZH_Controls.Controls.UCConveyor();
this.SuspendLayout();
//
// ucBottle1
//
this.ucBottle1.BottleColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucBottle1.BottleMouthColor = System.Drawing.Color.FromArgb(((int)(((byte)(105)))), ((int)(((byte)(105)))), ((int)(((byte)(105)))));
this.ucBottle1.LiquidColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243)))));
this.ucBottle1.Location = new System.Drawing.Point(816, -16);
this.ucBottle1.MaxValue = new decimal(new int[] {
100,
0,
0,
0});
this.ucBottle1.Name = "ucBottle1";
this.ucBottle1.NO = "1#";
this.ucBottle1.Size = new System.Drawing.Size(73, 168);
this.ucBottle1.TabIndex = 20;
this.ucBottle1.Title = "瓶子1";
this.ucBottle1.Value = new decimal(new int[] {
50,
0,
0,
0});
// ucConveyor2
//
this.ucConveyor2.BackColor = System.Drawing.Color.Transparent;
this.ucConveyor2.ConveyorColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucConveyor2.ConveyorDirection = HZH_Controls.Controls.ConveyorDirection.Forward;
this.ucConveyor2.ConveyorHeight = 30;
this.ucConveyor2.ConveyorSpeed = 100;
this.ucConveyor2.Inclination = 30D;
this.ucConveyor2.Location = new System.Drawing.Point(850, 439);
this.ucConveyor2.Name = "ucConveyor2";
this.ucConveyor2.Size = new System.Drawing.Size(183, 154);
this.ucConveyor2.TabIndex = 21;
//
// ucConveyor4
//
this.ucConveyor4.BackColor = System.Drawing.Color.Transparent;
this.ucConveyor4.ConveyorColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucConveyor4.ConveyorDirection = HZH_Controls.Controls.ConveyorDirection.Forward;
this.ucConveyor4.ConveyorHeight = 30;
this.ucConveyor4.ConveyorSpeed = 100;
this.ucConveyor4.Inclination = 90D;
this.ucConveyor4.Location = new System.Drawing.Point(742, 396);
this.ucConveyor4.Name = "ucConveyor4";
this.ucConveyor4.Size = new System.Drawing.Size(72, 197);
this.ucConveyor4.TabIndex = 21;
//
// ucConveyor3
//
this.ucConveyor3.BackColor = System.Drawing.Color.Transparent;
this.ucConveyor3.ConveyorColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucConveyor3.ConveyorDirection = HZH_Controls.Controls.ConveyorDirection.Forward;
this.ucConveyor3.ConveyorHeight = 30;
this.ucConveyor3.ConveyorSpeed = 100;
this.ucConveyor3.Inclination = 0D;
this.ucConveyor3.Location = new System.Drawing.Point(820, 380);
this.ucConveyor3.Name = "ucConveyor3";
this.ucConveyor3.Size = new System.Drawing.Size(213, 53);
this.ucConveyor3.TabIndex = 21;
//
// ucConveyor1
//
this.ucConveyor1.BackColor = System.Drawing.Color.Transparent;
this.ucConveyor1.ConveyorColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucConveyor1.ConveyorDirection = HZH_Controls.Controls.ConveyorDirection.Forward;
this.ucConveyor1.ConveyorHeight = 30;
this.ucConveyor1.ConveyorSpeed = 100;
this.ucConveyor1.Inclination = -30D;
this.ucConveyor1.Location = new System.Drawing.Point(1039, 428);
this.ucConveyor1.Name = "ucConveyor1";
this.ucConveyor1.Size = new System.Drawing.Size(183, 157);
this.ucConveyor1.TabIndex = 21;
//
// ucConduit9
//
......@@ -378,11 +415,87 @@
this.ucConduit1.Size = new System.Drawing.Size(136, 37);
this.ucConduit1.TabIndex = 19;
//
// ucBottle2
//
this.ucBottle2.BottleColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucBottle2.BottleMouthColor = System.Drawing.Color.FromArgb(((int)(((byte)(105)))), ((int)(((byte)(105)))), ((int)(((byte)(105)))));
this.ucBottle2.LiquidColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243)))));
this.ucBottle2.Location = new System.Drawing.Point(1032, 12);
this.ucBottle2.MaxValue = new decimal(new int[] {
100,
0,
0,
0});
this.ucBottle2.Name = "ucBottle2";
this.ucBottle2.NO = "1#";
this.ucBottle2.Size = new System.Drawing.Size(73, 168);
this.ucBottle2.TabIndex = 20;
this.ucBottle2.Title = "瓶子1";
this.ucBottle2.Value = new decimal(new int[] {
50,
0,
0,
0});
//
// ucBottle1
//
this.ucBottle1.BottleColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucBottle1.BottleMouthColor = System.Drawing.Color.FromArgb(((int)(((byte)(105)))), ((int)(((byte)(105)))), ((int)(((byte)(105)))));
this.ucBottle1.LiquidColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243)))));
this.ucBottle1.Location = new System.Drawing.Point(816, 2);
this.ucBottle1.MaxValue = new decimal(new int[] {
100,
0,
0,
0});
this.ucBottle1.Name = "ucBottle1";
this.ucBottle1.NO = "1#";
this.ucBottle1.Size = new System.Drawing.Size(73, 150);
this.ucBottle1.TabIndex = 20;
this.ucBottle1.Title = "";
this.ucBottle1.Value = new decimal(new int[] {
50,
0,
0,
0});
//
// ucConveyor5
//
this.ucConveyor5.BackColor = System.Drawing.Color.Transparent;
this.ucConveyor5.ConveyorColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucConveyor5.ConveyorDirection = HZH_Controls.Controls.ConveyorDirection.Backward;
this.ucConveyor5.ConveyorHeight = 30;
this.ucConveyor5.ConveyorSpeed = 100;
this.ucConveyor5.Inclination = 0D;
this.ucConveyor5.Location = new System.Drawing.Point(1039, 380);
this.ucConveyor5.Name = "ucConveyor5";
this.ucConveyor5.Size = new System.Drawing.Size(213, 53);
this.ucConveyor5.TabIndex = 21;
//
// ucConveyor6
//
this.ucConveyor6.BackColor = System.Drawing.Color.Transparent;
this.ucConveyor6.ConveyorColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucConveyor6.ConveyorDirection = HZH_Controls.Controls.ConveyorDirection.Backward;
this.ucConveyor6.ConveyorHeight = 30;
this.ucConveyor6.ConveyorSpeed = 100;
this.ucConveyor6.Inclination = 90D;
this.ucConveyor6.Location = new System.Drawing.Point(1258, 396);
this.ucConveyor6.Name = "ucConveyor6";
this.ucConveyor6.Size = new System.Drawing.Size(72, 197);
this.ucConveyor6.TabIndex = 21;
//
// Form4
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(1368, 680);
this.Controls.Add(this.ucConveyor2);
this.Controls.Add(this.ucConveyor6);
this.Controls.Add(this.ucConveyor4);
this.Controls.Add(this.ucConveyor5);
this.Controls.Add(this.ucConveyor3);
this.Controls.Add(this.ucConveyor1);
this.Controls.Add(this.ucConduit9);
this.Controls.Add(this.ucConduit22);
this.Controls.Add(this.ucConduit24);
......@@ -408,6 +521,7 @@
this.Controls.Add(this.ucConduit11);
this.Controls.Add(this.ucConduit10);
this.Controls.Add(this.ucConduit1);
this.Controls.Add(this.ucBottle2);
this.Controls.Add(this.ucBottle1);
this.Name = "Form4";
this.Text = "Form4";
......@@ -443,5 +557,12 @@
private HZH_Controls.Controls.Conduit.UCConduit ucConduit25;
private HZH_Controls.Controls.Conduit.UCConduit ucConduit27;
private HZH_Controls.Controls.UCBottle ucBottle1;
private HZH_Controls.Controls.UCBottle ucBottle2;
private HZH_Controls.Controls.UCConveyor ucConveyor1;
private HZH_Controls.Controls.UCConveyor ucConveyor2;
private HZH_Controls.Controls.UCConveyor ucConveyor3;
private HZH_Controls.Controls.UCConveyor ucConveyor4;
private HZH_Controls.Controls.UCConveyor ucConveyor5;
private HZH_Controls.Controls.UCConveyor ucConveyor6;
}
}
\ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!