上传界面显示
This commit is contained in:
126
DH.UI.Model.Winform/IOIndicatorCtrl.cs
Normal file
126
DH.UI.Model.Winform/IOIndicatorCtrl.cs
Normal file
@ -0,0 +1,126 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user