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.

151 lines
3.7 KiB
C#

1 year ago
using System;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
namespace Mesnac.Controls.Feeding
{
/// <summary>
/// 导开机
/// </summary>
[ToolboxBitmap( typeof( BatchFeeder ) , "ICONS.BatchFeeder.bmp" )]//新添加的代码
public partial class BatchFeeder : FeedingControl
{
bool bNewPic = false;
bool bSreamPic = false;
string _statusName;
public string StatusName
{
get
{
return _statusName;
}
set
{
_statusName = value;
}
}
public enum Statuses
{
//dkNull = 0, dkFull = 1, dkMove = 2, dkAlarm=3
dkNull = 0, dkMove = 1, dkFull = 2, dkAlarm = 3
}
Statuses _status;
string[] sImages;
public BatchFeeder()
: base()
{
InitializeComponent();
Init();
ReloadStream();
this.Reload();
}
protected override void Init()
{
base.Init();
_imageStream = null;
sImages = new string[4];
sImages[0] = "Mesnac.Controls.Feeding.Resources.dkj.dkNull.png";//dkNull
sImages[1] = "Mesnac.Controls.Feeding.Resources.dkj.dkMove.gif";//dkMove
sImages[2] = "Mesnac.Controls.Feeding.Resources.dkj.dkFull.png";//dkFull
sImages[3] = "Mesnac.Controls.Feeding.Resources.dkj.dkAlarm.gif";//dkAlarm
_status = Statuses.dkNull;
}
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.dkNull;
}
else if ( (int)value > 3 )
{
_status = Statuses.dkAlarm;
}
else
{
_status = value;
}
//if ((int)value != 1)
//{
// this._status = (Statuses)2;
//}
if (bSreamPic)
{
ReloadStream();
this.Refresh();
this.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();
}
}
private void BatchFeeder_Load(object sender, EventArgs e)
{
if (bFirstCreated == true && this.DesignMode == true)
{
bNewPic = true;
bFirstCreated = false;
this.Reload();
}
}
}
}