127 lines
2.7 KiB
C#
127 lines
2.7 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace XKRS.UI.Model.Winform
|
|
{
|
|
public partial class IOIndicatorCtrl : UserControl
|
|
{
|
|
public IOIndicatorCtrl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private bool isON = false;
|
|
|
|
public bool IsOn
|
|
{
|
|
get => isON;
|
|
set
|
|
{
|
|
bool? temp = isON;
|
|
isON = value;
|
|
|
|
if (temp != isON)
|
|
{
|
|
RefreshStatus();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void RefreshStatus()
|
|
{
|
|
if (InvokeRequired)
|
|
{
|
|
Invoke(new Action(() => RefreshStatus()));
|
|
}
|
|
else
|
|
{
|
|
plStatus.Invalidate();
|
|
}
|
|
}
|
|
|
|
private string desc = "";
|
|
public string Desc
|
|
{
|
|
get => desc;
|
|
set
|
|
{
|
|
desc = value;
|
|
|
|
DisplayDesc();
|
|
}
|
|
}
|
|
|
|
public int Index { get; set; }
|
|
|
|
private void DisplayDesc()
|
|
{
|
|
if (InvokeRequired)
|
|
{
|
|
Invoke(new Action(() => DisplayDesc()));
|
|
}
|
|
else
|
|
{
|
|
lblDesc.Text = Desc;
|
|
}
|
|
}
|
|
|
|
readonly PointF[] regionBlink = new PointF[]
|
|
{
|
|
new PointF(5,10),
|
|
new PointF(10,13),
|
|
new PointF(12,7),
|
|
new PointF(10,5)
|
|
};
|
|
|
|
public IOIndicatorCtrl(bool _isOn, string _desc, int index = 0)
|
|
{
|
|
InitializeComponent();
|
|
|
|
IsOn = _isOn;
|
|
Desc = _desc;
|
|
Index = index;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新绘制图标
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void plStatus_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
Panel pl = sender as Panel;
|
|
|
|
Graphics g = e.Graphics;
|
|
|
|
g.Clear(SystemColors.Control);
|
|
|
|
|
|
if (IsOn)
|
|
{
|
|
g.FillEllipse(Brushes.LightGreen, pl.ClientRectangle);
|
|
}
|
|
else
|
|
{
|
|
g.FillEllipse(Brushes.Gray, pl.ClientRectangle);
|
|
}
|
|
|
|
g.FillPolygon(Brushes.White, regionBlink);
|
|
|
|
}
|
|
|
|
public event Action<string, bool, int> OnIODoubleClick;
|
|
|
|
|
|
private void lblDesc_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
OnIODoubleClick?.Invoke(Name, IsOn, Index);
|
|
}
|
|
|
|
private void plStatus_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
OnIODoubleClick?.Invoke(Name, IsOn, Index);
|
|
}
|
|
}
|
|
}
|