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.../SwitchLight.cs

163 lines
4.2 KiB
C#

1 year ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesnac.Controls.ChemicalWeighing
{ /// <summary>
/// 开关灯
/// </summary>
[ToolboxBitmap(typeof(AlarmLight), "Resources.AlarmLight.bmp")]//新添加的代码
public partial class SwitchLight : ChemicalWeighingControl
{
bool bNewPic = false;
string _statusName;
public string StatusName
{
get
{
return _statusName;
}
set
{
_statusName = value;
}
}
public enum Statuses
{
12 months ago
ylNormal = 0, ylMove = 1, ylAlarm = 2,ylWeiXiu=3
1 year ago
}
Statuses _status;
string[] sImages;
public SwitchLight() : base()
{
InitializeComponent();
Init();
ReloadStream();
}
protected override void Init()
{
base.Init();
_imageStream = null;
12 months ago
sImages = new string[4];
1 year ago
sImages[0] = "Mesnac.Controls.ChemicalWeighing.Resources.AlarmLightNewGray.png";//
sImages[1] = "Mesnac.Controls.ChemicalWeighing.Resources.AlarmLightNewGreen.png";//
sImages[2] = "Mesnac.Controls.ChemicalWeighing.Resources.AlarmLightNewRed.png";//
12 months ago
sImages[3] = "Mesnac.Controls.ChemicalWeighing.Resources.AlarmLightPurple.png";//
1 year ago
_status = Statuses.ylNormal;
}
private void ReloadStream()
{
//CloseStream();
int nIndex = (int)_status;
_imageStream = _assembly.GetManifestResourceStream(sImages[nIndex]);
}
public Statuses Status
{
get
{
return _status;
}
set
{
if (bFirstCreated == true)
{
bFirstCreated = false;
}
//if (_status != value &&(this.Size.Width != 150 || this.Size.Height != 150) )
if (_status != value)
{
if (this.DesignMode == true)
{
bNewPic = true;
}
}
12 months ago
var val = (int)value;
if (val == 0)
1 year ago
{
_status = (Statuses)0;
}
12 months ago
if (val == 1)
{
_status = (Statuses)1;
}
if (val == 2)
1 year ago
{
_status = (Statuses)2;
}
12 months ago
if (val == 3)
{
_status = (Statuses)3;
}
if (val == 4)
1 year ago
{
12 months ago
_status = (Statuses)4;
1 year ago
}
12 months ago
1 year ago
ReloadStream();
Reload();
}
}
private void Reload()
{
if (_imageStream != null)
{
Image img = Image.FromStream(_imageStream);
if (bNewPic == true)
{
//this.Size = img.Size;
bNewPic = false;
}
pictureBox1.Image = img;
pictureBox1.Refresh();
}
}
protected override void OnPaint(PaintEventArgs e)
{
if (_imageStream != null)
{
Graphics g = e.Graphics;
Image img = Image.FromStream(_imageStream);
if (bNewPic == true)
{
//this.Size = img.Size;
bNewPic = false;
}
g.DrawImage(img, 0, 0, this.Width, this.Height);
}
}
private void PressureSwitch_Load(object sender, EventArgs e)
{
if (bFirstCreated == true && this.DesignMode == true)
{
bNewPic = true;
bFirstCreated = false;
Reload();
}
}
}
}