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/clfbdcf.cs

148 lines
3.9 KiB
C#

2 years ago
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(clfbdcf), "Resources.clfbdcf.clfbdcf0.png")]//新添加的代码
public partial class clfbdcf : FeedingControl
2 years ago
{
public enum Statuses
{
TurnOff = 0,
TurnOn = 1
2 years ago
}
private bool bNewPic = false;
private string _statusName;
private Statuses _status;
private string[] sImages;
public clfbdcf():base()
2 years ago
{
InitializeComponent();
Init();
ReloadStream();
this.Reload();
}
private void clfbdcf_Load(object sender, EventArgs e)
2 years ago
{
if (bFirstCreated == true && this.DesignMode == true)
{
bNewPic = true;
bFirstCreated = false;
Reload();
}
}
protected override void Init()
{
base.Init();
_imageStream = null;
sImages = new string[2];
sImages[0] = "Mesnac.Controls.Feeding.Resources.clfbdcf.clfbdcf0.png";//zsTurnOn
sImages[1] = "Mesnac.Controls.Feeding.Resources.clfbdcf.clfbdcf1.png";//zsTurnOn
2 years ago
_status = Statuses.TurnOff;
2 years ago
}
private void ReloadStream()
{
int nIndex = (int)_status;
_imageStream = _assembly.GetManifestResourceStream(sImages[nIndex]);
}
public string StatusName
{
get
{
return _statusName;
}
set
{
_statusName = value;
}
}
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)
2 years ago
{
_status = (Statuses)0;
2 years ago
}
else if ((int)value > 1)
2 years ago
{
_status = (Statuses)1;
2 years ago
}
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;
}
2 years ago
g.DrawImage(img, 0, 0, this.Width, this.Height);
}
}
2 years ago
private void Reload()
{
if (_imageStream != null)
{
Image img = Image.FromStream(_imageStream);
Size size = new Size();
size.Width = 26;
size.Height = 6;
this.Size = size;
2 years ago
if (bNewPic == true)
{
this.Size = size;
2 years ago
bNewPic = false;
}
pictureBox1.Image = img;
pictureBox1.Refresh();
}
}
}
}