using System; using System.Drawing; using System.IO; using System.Reflection; using System.Windows.Forms; namespace Mesnac.Controls.Feeding { /// /// 传送带 /// [ToolboxBitmap(typeof(TransmissionBelt), "ICONS.TransmissionBelt.bmp")]//新添加的代码 public partial class TransmissionBelt : FeedingControl { bool bNewPic = false; bool bSreamPic = false; string _statusName; private string _sensorStatusName; private string _csdMotorStatusName; public string StatusName { get { return _statusName; } set { _statusName = value; } } /// /// 传送带光电开关状态动画属性 /// public string SensorStatusName { get { return _sensorStatusName; } set { _sensorStatusName = value; } } /// /// 传送带电机状态动画属性 /// public string CsdMotorStatusName { get { return _csdMotorStatusName; } set { _csdMotorStatusName = value; } } public enum Statuses { //csdNull = 0, csdWeight = 1, csdFull = 2, csdUnload = 3, csdAlarm = 4 csdNull = 0, csdWeight = 1, csdFull = 2, csdUnload = 3 } Statuses _status; private OnOffStatuses _sensorStatus; private OnOffStatuses _csdMotorStatus; string[] sImages; public TransmissionBelt():base() { InitializeComponent(); Init(); ReloadStream(); this.Reload(); } protected override void Init() { base.Init(); _imageStream = null; sImages = new string[4]; sImages[ 0 ] = "Mesnac.Controls.Feeding.Resources.csd.csd_null.png";// sImages[ 1 ] = "Mesnac.Controls.Feeding.Resources.csd.csd_weight.gif";// sImages[ 2 ] = "Mesnac.Controls.Feeding.Resources.csd.csd_full.png";// sImages[ 3 ] = "Mesnac.Controls.Feeding.Resources.csd.csd_unload.gif";// _status = Statuses.csdNull; } 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 ) { bSreamPic = true; if (this.DesignMode == true) { bNewPic = true; } } if ( (int)value < 0 ) { _status = (Statuses)0; } else if ( (int)value > 3 ) { _status = (Statuses)3; } else { _status = value; } if (bSreamPic) { ReloadStream(); this.Reload(); } } } /// /// 光电开关状态 /// public OnOffStatuses SensorStatus { get { return this._sensorStatus; } set { if ((int)value > 1) { this._sensorStatus = OnOffStatuses.On; } else if ((int)value < 0) { this._sensorStatus = OnOffStatuses.Off; } else { this._sensorStatus = value; } this.UpdateStatus(); } } /// /// 传输带电机状态 /// public OnOffStatuses CsdMotorStatus { get { return _csdMotorStatus; } set { bool flag = false; if (this._csdMotorStatus != value) flag = true; if ((int)value > 1) { this._csdMotorStatus = OnOffStatuses.On; } else if ((int)value < 0) { this._csdMotorStatus = OnOffStatuses.Off; } else { this._csdMotorStatus = value; } if (flag) this.UpdateStatus(); } } /// /// 更新传送带状态 /// private void UpdateStatus() { if (this._sensorStatus == OnOffStatuses.On && this._csdMotorStatus == OnOffStatuses.On) { this._status = Statuses.csdUnload; } else if (this._sensorStatus == OnOffStatuses.Off && this._csdMotorStatus == OnOffStatuses.On) { this._status = Statuses.csdWeight; } else if (this._sensorStatus == OnOffStatuses.On && this._csdMotorStatus == OnOffStatuses.Off) { this.Status = Statuses.csdFull; } else if (this._sensorStatus == OnOffStatuses.Off && this._csdMotorStatus == OnOffStatuses.Off) { this.Status = Statuses.csdNull; } ReloadStream(); this.Reload(); } private void Reload() { if (_imageStream != null) { Image img = Image.FromStream(_imageStream); if (bNewPic == true) { //this.Size = img.Size; this.Size = new System.Drawing.Size(98, 54); bNewPic = false; } this.pictureBox1.Image = img; this.pictureBox1.Refresh(); } } private void TransmissionBelt_Load(object sender, EventArgs e) { if (bFirstCreated == true && this.DesignMode == true) { bNewPic = true; bFirstCreated = false; } } } }