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 { [ToolboxBitmap(typeof(Diverter), "Resources.diverter.hxfz0.png")]//新添加的代码 public partial class Diverter : FeedingControl { public enum Types { hxfLeft = 0, hxfRight = 1 } public enum Statuses { fmTurnOff = 0, fmTurnOn = 1 } private bool bNewPic = false; private string _statusName; private Statuses _status; private string[,] sImages; private Types _type; public Diverter():base() { InitializeComponent(); Init(); ReloadStream(); this.Reload(); } private void Diverter_Load(object sender, EventArgs e) { if (bFirstCreated == true && this.DesignMode == true) { bNewPic = true; bFirstCreated = false; Reload(); } } protected override void Init() { base.Init(); _imageStream = null; sImages = new string[2,2]; sImages[0, 0] = "Mesnac.Controls.Feeding.Resources.diverter.hxfz0.png";//zsTurnOn sImages[0, 1] = "Mesnac.Controls.Feeding.Resources.diverter.hxfz1.png";//zsTurnOn sImages[1, 0] = "Mesnac.Controls.Feeding.Resources.diverter.hxfy0.png";//zsTurnOn sImages[1, 1] = "Mesnac.Controls.Feeding.Resources.diverter.hxfy1.png";//zsTurnOn //sImages[2] = "Mesnac.Controls.Feeding.Resources.famen.Famen1.png";//zsTurnOff //sImages[3] = "Mesnac.Controls.Feeding.Resources.famen.Famen2.png";//zsAlarm _type = Types.hxfLeft; //初始类型 _status = Statuses.fmTurnOff; } private void ReloadStream() { int ntype = (int)_type; int nIndex = (int)_status; _imageStream = _assembly.GetManifestResourceStream(sImages[ntype, nIndex]); } public string StatusName { get { return _statusName; } set { _statusName = value; } } public Types Type { get { return _type; } set { if (bFirstCreated == true) { bFirstCreated = false; } if (_type != value) { if (this.DesignMode == true) { bNewPic = true; } } _type = value; ReloadStream(); //this.Refresh(); this.Reload(); } } 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; } else if ((int)value >= 2) { _status = (Statuses)1; } else { _status = value; } if (flag) { ReloadStream(); Reload(); this.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 Reload() { if (_imageStream != null) { Image img = Image.FromStream(_imageStream); Size size = new Size(); size.Width = 81; size.Height = 24; this.Size = size; if (bNewPic == true) { this.Size = size; bNewPic = false; } pictureBox1.Image = img; pictureBox1.Refresh(); } } } }