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.
lj_plc/Controls/Mesnac.Controls.ChemicalWei.../SwithDMLight.cs

86 lines
2.1 KiB
C#

using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
namespace Mesnac.Controls.ChemicalWeighing
{
[ToolboxBitmap(typeof(SwithDMLight), "Resources.AlarmLight.bmp")]//新添加的代码
public partial class SwithDMLight : ChemicalWeighingControl
{
private string[] sImages = new string[3];
private bool _running;
private bool _alarm;
public SwithDMLight()
{
InitializeComponent();
_assembly = Assembly.GetExecutingAssembly();
sImages[0] = "Mesnac.Controls.ChemicalWeighing.Resources.AlarmLightNewGray.png";//
sImages[1] = "Mesnac.Controls.ChemicalWeighing.Resources.AlarmLightNewGreen.png";//
sImages[2] = "Mesnac.Controls.ChemicalWeighing.Resources.AlarmLightNewRed.png";//
}
public string RunningName { get; set; }
public string AlarmName { get; set; }
public bool Running
{
get => _running;
set
{
_running = value;
R();
}
}
public bool Alarm
{
get => _alarm;
set
{
_alarm = value;
R();
}
}
private void Reload()
{
if ( _imageStream != null )
{
Image img = Image.FromStream( _imageStream);
pictureBox1.Image = img;
pictureBox1.Refresh();
}
}
private void ReloadStream()
{
int defaultIndex = 0;
//如果出现报警 就去判断是直还是斜
if (Alarm)
{
defaultIndex = 2;
}
else
{
if (Running)
{
defaultIndex = 1;
}
}
_imageStream = _assembly.GetManifestResourceStream(sImages[defaultIndex]);
}
private void R()
{
ReloadStream();
Reload();
}
}
}