using Mesnac.Controls.Base; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Mesnac.Controls.Feeding { public partial class NewFan : FeedingControl { #region 事件定义 /// /// 报警事件 /// public event EventHandler OnAlarm; #endregion #region 事件属性 private List _alarmActionList = new List(); public List AlarmActionList { get { return _alarmActionList; } set { _alarmActionList = value; } } #endregion bool bNewPic = false; string _statusName; private string _alarmValue; private string _alarmValue_; /// /// 报警信息属性 /// public string AlarmValue { get { return _alarmValue; } set { _alarmValue = value; } } /// /// 报警信息 /// [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 } Statuses _status; string[] sImages; public NewFan() : base() { InitializeComponent(); Init(); ReloadStream(); this.Reload(); } protected override void Init() { base.Init(); _imageStream = null; sImages = new string[2]; sImages[0] = "Mesnac.Controls.Feeding.Resources.Fan.newfan.png";//zsTurnOff sImages[1] = "Mesnac.Controls.Feeding.Resources.Fan.newfan1.gif";//zsTurnOn _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 < 1 ) //{ // _status = (Statuses)1; //} if ((int)value > 1) { _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(); } } } }