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.Feeding/Fan.cs

208 lines
5.5 KiB
C#

using System;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using Mesnac.Controls.Base;
using System.Collections.Generic;
namespace Mesnac.Controls.Feeding
{
/// <summary>
/// 风机
/// </summary>
[ToolboxBitmap( typeof( Fan ) , "ICONS.Fan.bmp" )]//新添加的代码
public partial class Fan : FeedingControl
{
#region 事件定义
/// <summary>
/// 报警事件
/// </summary>
public event EventHandler OnAlarm;
#endregion
#region 事件属性
private List<DesignAction> _alarmActionList = new List<DesignAction>();
public List<DesignAction> AlarmActionList
{
get { return _alarmActionList; }
set { _alarmActionList = value; }
}
#endregion
bool bNewPic = false;
string _statusName;
private string _alarmValue;
private string _alarmValue_;
/// <summary>
/// 报警信息属性
/// </summary>
public string AlarmValue
{
get { return _alarmValue; }
set { _alarmValue = value; }
}
/// <summary>
/// 报警信息
/// </summary>
[Alarm]
public string AlarmValue_
{
get { return _alarmValue_; }
set { _alarmValue_ = value; }
}
public string StatusName
{
get
{
return _statusName;
}
set
{
_statusName = value;
}
}
public enum Statuses
{
zsTurnOff = 0,
zsTurnOn = 1,
zsAlarm = 2,
}
Statuses _status;
string[] sImages;
public Fan():base()
{
InitializeComponent();
Init();
ReloadStream();
this.Reload();
}
protected override void Init()
{
base.Init();
_imageStream = null;
sImages = new string[ 3 ];
//sImages[ 0 ] = "Mesnac.Controls.Feeding.Resources.Fan.Fan00.gif";//zsTurnOn
//sImages[ 1 ] = "Mesnac.Controls.Feeding.Resources.Fan.Fan01.png";//zsTurnOff
//sImages[ 2 ] = "Mesnac.Controls.Feeding.Resources.Fan.Fan02.gif";//zsAlarm
sImages[0] = "Mesnac.Controls.Feeding.Resources.Fan.F2.png";//zsTurnOff
sImages[1] = "Mesnac.Controls.Feeding.Resources.Fan.FD2.gif";//zsTurnOn
sImages[2] = "Mesnac.Controls.Feeding.Resources.Fan.FA2.gif";//zsAlarm
//sImages[2] = "Mesnac.Controls.Feeding.Resources.Fan.Fan02.gif";//zsAlarm
//sImages[ 3 ] = "Mesnac.Controls.Feeding.Resources.Fan.F2.png";//zsTurnOff
//sImages[ 4 ] = "Mesnac.Controls.Feeding.Resources.Fan.FD2.gif";//zsTurnOn
//sImages[ 5 ] = "Mesnac.Controls.Feeding.Resources.Fan.FA2.gif";//zsAlarm
_status = Statuses.zsTurnOff;
}
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;
}
bool flag = false;
//if (_status != value &&(this.Size.Width != 150 || this.Size.Height != 150) )
if ( _status != value )
{
flag = true;
if (this.DesignMode == true)
{
bNewPic = true;
}
}
if ((int)value < 0)
{
_status = (Statuses)0;
}
if ( (int)value > 2 )
{
_status = (Statuses)1;
}
else
{
_status = value;
}
if (flag)
{
ReloadStream();
this.Reload();
//if (_status == Statuses.zsAlarm)
//{
// this._alarmValue_ = this._alarmValue; //设置报警信息
//}
//else
//{
// this._alarmValue_ = String.Empty; //清空报警信息
//}
//有事件订阅者,则触发报警事件
if (OnAlarm != null)
{
OnAlarm(this, System.EventArgs.Empty);
}
}
}
}
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();
}
}
private void Fan_Load(object sender, EventArgs e)
{
if (bFirstCreated == true && this.DesignMode == true)
{
bNewPic = true;
bFirstCreated = false;
Reload();
}
}
}
}