You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
4.1 KiB
C#
121 lines
4.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Rs.Controls
|
|
{
|
|
public class IOStatus : Label
|
|
{
|
|
|
|
private bool _ShowNo = true;
|
|
|
|
public bool ShowNo
|
|
{
|
|
get { return _ShowNo; }
|
|
set { _ShowNo = value; }
|
|
}
|
|
|
|
private ushort _IoNO;
|
|
|
|
public ushort IoNO
|
|
{
|
|
get { return _IoNO; }
|
|
set { _IoNO = value; }
|
|
}
|
|
|
|
private int _Radius = 5;
|
|
|
|
public int Radius
|
|
{
|
|
get { return _Radius; }
|
|
set { _Radius = value; }
|
|
}
|
|
|
|
private ushort _IoID;
|
|
|
|
public ushort IoID
|
|
{
|
|
get { return _IoID; }
|
|
set { _IoID = value; }
|
|
}
|
|
|
|
private Color fillColor = Color.Gray;
|
|
|
|
private int _Status = 1;
|
|
|
|
public int Status
|
|
{
|
|
get { return _Status; }
|
|
set
|
|
{
|
|
_Status = value;
|
|
if (_Status == 0)
|
|
{
|
|
this.fillColor = Color.Gray;
|
|
}
|
|
else
|
|
{
|
|
this.fillColor = Color.FromArgb(74, 164, 15);
|
|
}
|
|
Invalidate();
|
|
}
|
|
}
|
|
|
|
public IOStatus()
|
|
{
|
|
this.AutoSize = false;
|
|
this.FlatStyle = FlatStyle.Flat;
|
|
}
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
{
|
|
base.OnPaint(e);
|
|
Brush bs = new SolidBrush(fillColor);
|
|
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //使绘图质量最高,即消除锯齿
|
|
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
|
|
|
|
Rectangle rect = this.ClientRectangle;
|
|
|
|
GraphicsPath path = new GraphicsPath();
|
|
path.AddArc(new Rectangle(rect.Left, rect.Top, _Radius * 2, _Radius * 2), 180, 90);
|
|
path.AddLine(new Point(rect.Left + _Radius, rect.Top), new Point(rect.Left + rect.Width - _Radius, rect.Top));
|
|
|
|
path.AddArc(new Rectangle(rect.Left + rect.Width - 1 - (_Radius * 2), rect.Top, _Radius * 2, _Radius * 2), 270, 90);
|
|
|
|
path.AddLine(new Point(rect.Left + rect.Width - 1, rect.Top + _Radius), new Point(rect.Left + rect.Width - 1, rect.Top + rect.Height - _Radius));//右边竖线
|
|
|
|
path.AddArc(new Rectangle(rect.Left + rect.Width - 1 - (_Radius * 2), rect.Top + rect.Height - 1 - _Radius * 2, _Radius * 2, _Radius * 2), 0, 90);
|
|
|
|
path.AddLine(new Point(rect.Left + _Radius, rect.Top + rect.Height - 1), new Point(rect.Left + rect.Width - _Radius, rect.Top + rect.Height - 1));//右边竖线
|
|
|
|
path.AddArc(new Rectangle(rect.Left, rect.Top + rect.Height - 1 - _Radius * 2, _Radius * 2, _Radius * 2), 90, 90);
|
|
|
|
path.AddLine(new Point(rect.Left, rect.Top + _Radius), new Point(rect.Left, rect.Top + rect.Height - 1 - _Radius));//右边竖线
|
|
|
|
//e.Graphics.DrawPath(Pens.White, path);
|
|
|
|
e.Graphics.FillPath(bs, path);
|
|
SizeF size = e.Graphics.MeasureString(this.Text, this.Font);
|
|
|
|
e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), new PointF((this.Width - size.Width) / 2, (this.Height - size.Height) / 2));
|
|
if (ShowNo)
|
|
{
|
|
RectangleF yuanRect = new RectangleF(rect.Left, rect.Top, 20, 20);
|
|
e.Graphics.FillEllipse(new SolidBrush(Color.Red),yuanRect);
|
|
e.Graphics.DrawEllipse(new Pen(Color.White), yuanRect);
|
|
Font indexFont = new Font("宋体", 11);
|
|
SizeF nosize = e.Graphics.MeasureString(IoNO.ToString(), indexFont);
|
|
e.Graphics.DrawString(IoNO.ToString(), indexFont, new SolidBrush(ForeColor), new PointF(yuanRect.Left + (yuanRect.Width - nosize.Width) / 2, yuanRect.Top + (yuanRect.Height - nosize.Height) / 2));
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|