Commit c2b25bd3 HZH

箭头

1 个父辈 a3a7b52b
// ***********************************************************************
// 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();
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
}
}
...@@ -43,6 +43,9 @@ ...@@ -43,6 +43,9 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Controls\FactoryControls\Arrow\UCArrow.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\FactoryControls\Blower\UCBlower.cs"> <Compile Include="Controls\FactoryControls\Blower\UCBlower.cs">
<SubType>UserControl</SubType> <SubType>UserControl</SubType>
</Compile> </Compile>
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.ucArrow1 = new HZH_Controls.Controls.UCArrow();
this.ucAlarmLamp1 = new HZH_Controls.Controls.UCAlarmLamp(); this.ucAlarmLamp1 = new HZH_Controls.Controls.UCAlarmLamp();
this.ucSignalLamp1 = new HZH_Controls.Controls.UCSignalLamp(); this.ucSignalLamp1 = new HZH_Controls.Controls.UCSignalLamp();
this.ucBlower6 = new HZH_Controls.Controls.UCBlower(); this.ucBlower6 = new HZH_Controls.Controls.UCBlower();
...@@ -75,8 +76,25 @@ ...@@ -75,8 +76,25 @@
this.ucBottle1 = new HZH_Controls.Controls.UCBottle(); this.ucBottle1 = new HZH_Controls.Controls.UCBottle();
this.ucPond2 = new HZH_Controls.Controls.UCPond(); this.ucPond2 = new HZH_Controls.Controls.UCPond();
this.ucBlower4 = new HZH_Controls.Controls.UCBlower(); this.ucBlower4 = new HZH_Controls.Controls.UCBlower();
this.ucArrow2 = new HZH_Controls.Controls.UCArrow();
this.ucArrow3 = new HZH_Controls.Controls.UCArrow();
this.ucArrow4 = new HZH_Controls.Controls.UCArrow();
this.ucArrow5 = new HZH_Controls.Controls.UCArrow();
this.ucArrow6 = new HZH_Controls.Controls.UCArrow();
this.SuspendLayout(); this.SuspendLayout();
// //
// ucArrow1
//
this.ucArrow1.ArrowColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucArrow1.BorderColor = null;
this.ucArrow1.Direction = HZH_Controls.Controls.ArrowDirection.Right;
this.ucArrow1.ForeColor = System.Drawing.Color.White;
this.ucArrow1.Location = new System.Drawing.Point(1222, 383);
this.ucArrow1.Name = "ucArrow1";
this.ucArrow1.Size = new System.Drawing.Size(100, 50);
this.ucArrow1.TabIndex = 27;
this.ucArrow1.Text = "右";
//
// ucAlarmLamp1 // ucAlarmLamp1
// //
this.ucAlarmLamp1.LampColor = new System.Drawing.Color[] { this.ucAlarmLamp1.LampColor = new System.Drawing.Color[] {
...@@ -164,7 +182,7 @@ ...@@ -164,7 +182,7 @@
this.ucValve2.LiquidColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243))))); this.ucValve2.LiquidColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243)))));
this.ucValve2.LiquidDirection = HZH_Controls.Controls.Conduit.LiquidDirection.Forward; this.ucValve2.LiquidDirection = HZH_Controls.Controls.Conduit.LiquidDirection.Forward;
this.ucValve2.LiquidSpeed = 100; this.ucValve2.LiquidSpeed = 100;
this.ucValve2.Location = new System.Drawing.Point(1222, 279); this.ucValve2.Location = new System.Drawing.Point(1222, 158);
this.ucValve2.Name = "ucValve2"; this.ucValve2.Name = "ucValve2";
this.ucValve2.Opened = true; this.ucValve2.Opened = true;
this.ucValve2.Size = new System.Drawing.Size(97, 131); this.ucValve2.Size = new System.Drawing.Size(97, 131);
...@@ -176,7 +194,7 @@ ...@@ -176,7 +194,7 @@
// ucPond1 // ucPond1
// //
this.ucPond1.LiquidColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243))))); this.ucPond1.LiquidColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243)))));
this.ucPond1.Location = new System.Drawing.Point(1206, 384); this.ucPond1.Location = new System.Drawing.Point(1206, 263);
this.ucPond1.MaxValue = new decimal(new int[] { this.ucPond1.MaxValue = new decimal(new int[] {
100, 100,
0, 0,
...@@ -200,7 +218,7 @@ ...@@ -200,7 +218,7 @@
this.ucValve4.LiquidColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243))))); this.ucValve4.LiquidColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243)))));
this.ucValve4.LiquidDirection = HZH_Controls.Controls.Conduit.LiquidDirection.Backward; this.ucValve4.LiquidDirection = HZH_Controls.Controls.Conduit.LiquidDirection.Backward;
this.ucValve4.LiquidSpeed = 100; this.ucValve4.LiquidSpeed = 100;
this.ucValve4.Location = new System.Drawing.Point(1079, 52); this.ucValve4.Location = new System.Drawing.Point(1073, 52);
this.ucValve4.Name = "ucValve4"; this.ucValve4.Name = "ucValve4";
this.ucValve4.Opened = true; this.ucValve4.Opened = true;
this.ucValve4.Size = new System.Drawing.Size(169, 106); this.ucValve4.Size = new System.Drawing.Size(169, 106);
...@@ -216,7 +234,7 @@ ...@@ -216,7 +234,7 @@
this.ucValve1.LiquidColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243))))); this.ucValve1.LiquidColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243)))));
this.ucValve1.LiquidDirection = HZH_Controls.Controls.Conduit.LiquidDirection.Backward; this.ucValve1.LiquidDirection = HZH_Controls.Controls.Conduit.LiquidDirection.Backward;
this.ucValve1.LiquidSpeed = 100; this.ucValve1.LiquidSpeed = 100;
this.ucValve1.Location = new System.Drawing.Point(910, 12); this.ucValve1.Location = new System.Drawing.Point(904, 12);
this.ucValve1.Name = "ucValve1"; this.ucValve1.Name = "ucValve1";
this.ucValve1.Opened = true; this.ucValve1.Opened = true;
this.ucValve1.Size = new System.Drawing.Size(169, 106); this.ucValve1.Size = new System.Drawing.Size(169, 106);
...@@ -232,7 +250,7 @@ ...@@ -232,7 +250,7 @@
this.ucValve3.LiquidColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243))))); this.ucValve3.LiquidColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(169)))), ((int)(((byte)(243)))));
this.ucValve3.LiquidDirection = HZH_Controls.Controls.Conduit.LiquidDirection.Forward; this.ucValve3.LiquidDirection = HZH_Controls.Controls.Conduit.LiquidDirection.Forward;
this.ucValve3.LiquidSpeed = 100; this.ucValve3.LiquidSpeed = 100;
this.ucValve3.Location = new System.Drawing.Point(1259, 148); this.ucValve3.Location = new System.Drawing.Point(1259, 27);
this.ucValve3.Name = "ucValve3"; this.ucValve3.Name = "ucValve3";
this.ucValve3.Opened = true; this.ucValve3.Opened = true;
this.ucValve3.Size = new System.Drawing.Size(97, 131); this.ucValve3.Size = new System.Drawing.Size(97, 131);
...@@ -710,11 +728,77 @@ ...@@ -710,11 +728,77 @@
this.ucBlower4.Size = new System.Drawing.Size(116, 154); this.ucBlower4.Size = new System.Drawing.Size(116, 154);
this.ucBlower4.TabIndex = 24; this.ucBlower4.TabIndex = 24;
// //
// ucArrow2
//
this.ucArrow2.ArrowColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucArrow2.BorderColor = null;
this.ucArrow2.Direction = HZH_Controls.Controls.ArrowDirection.Left;
this.ucArrow2.ForeColor = System.Drawing.Color.White;
this.ucArrow2.Location = new System.Drawing.Point(1112, 383);
this.ucArrow2.Name = "ucArrow2";
this.ucArrow2.Size = new System.Drawing.Size(100, 50);
this.ucArrow2.TabIndex = 27;
this.ucArrow2.Text = "左";
//
// ucArrow3
//
this.ucArrow3.ArrowColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucArrow3.BorderColor = null;
this.ucArrow3.Direction = HZH_Controls.Controls.ArrowDirection.Left_Right;
this.ucArrow3.ForeColor = System.Drawing.Color.White;
this.ucArrow3.Location = new System.Drawing.Point(1112, 438);
this.ucArrow3.Name = "ucArrow3";
this.ucArrow3.Size = new System.Drawing.Size(210, 50);
this.ucArrow3.TabIndex = 27;
this.ucArrow3.Text = "左右";
//
// ucArrow4
//
this.ucArrow4.ArrowColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucArrow4.BorderColor = null;
this.ucArrow4.Direction = HZH_Controls.Controls.ArrowDirection.Top;
this.ucArrow4.ForeColor = System.Drawing.Color.White;
this.ucArrow4.Location = new System.Drawing.Point(1148, 494);
this.ucArrow4.Name = "ucArrow4";
this.ucArrow4.Size = new System.Drawing.Size(64, 84);
this.ucArrow4.TabIndex = 27;
this.ucArrow4.Text = "上";
//
// ucArrow5
//
this.ucArrow5.ArrowColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucArrow5.BorderColor = null;
this.ucArrow5.Direction = HZH_Controls.Controls.ArrowDirection.Bottom;
this.ucArrow5.ForeColor = System.Drawing.Color.White;
this.ucArrow5.Location = new System.Drawing.Point(1148, 584);
this.ucArrow5.Name = "ucArrow5";
this.ucArrow5.Size = new System.Drawing.Size(64, 84);
this.ucArrow5.TabIndex = 27;
this.ucArrow5.Text = "下";
//
// ucArrow6
//
this.ucArrow6.ArrowColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucArrow6.BorderColor = null;
this.ucArrow6.Direction = HZH_Controls.Controls.ArrowDirection.Top_Bottom;
this.ucArrow6.ForeColor = System.Drawing.Color.White;
this.ucArrow6.Location = new System.Drawing.Point(1222, 495);
this.ucArrow6.Name = "ucArrow6";
this.ucArrow6.Size = new System.Drawing.Size(64, 173);
this.ucArrow6.TabIndex = 27;
this.ucArrow6.Text = "上下";
//
// 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.ucArrow5);
this.Controls.Add(this.ucArrow6);
this.Controls.Add(this.ucArrow4);
this.Controls.Add(this.ucArrow2);
this.Controls.Add(this.ucArrow3);
this.Controls.Add(this.ucArrow1);
this.Controls.Add(this.ucAlarmLamp1); this.Controls.Add(this.ucAlarmLamp1);
this.Controls.Add(this.ucSignalLamp1); this.Controls.Add(this.ucSignalLamp1);
this.Controls.Add(this.ucBlower6); this.Controls.Add(this.ucBlower6);
...@@ -817,5 +901,11 @@ ...@@ -817,5 +901,11 @@
private HZH_Controls.Controls.UCSignalLamp ucSignalLamp1; private HZH_Controls.Controls.UCSignalLamp ucSignalLamp1;
private HZH_Controls.Controls.UCPond ucPond2; private HZH_Controls.Controls.UCPond ucPond2;
private HZH_Controls.Controls.UCAlarmLamp ucAlarmLamp1; private HZH_Controls.Controls.UCAlarmLamp ucAlarmLamp1;
private HZH_Controls.Controls.UCArrow ucArrow1;
private HZH_Controls.Controls.UCArrow ucArrow2;
private HZH_Controls.Controls.UCArrow ucArrow3;
private HZH_Controls.Controls.UCArrow ucArrow4;
private HZH_Controls.Controls.UCArrow ucArrow5;
private HZH_Controls.Controls.UCArrow ucArrow6;
} }
} }
\ No newline at end of file \ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!