UpStation.cs 2.78 KB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MyClassLib;
namespace MyControlLib
{
    public partial class UpStation : UserControl
    {
        public UpStation()
        {
            InitializeComponent();
            timer1.Enabled = true;
        }

        public bool _Sensor;

        public bool Sensor
        {
            get { return _Sensor; }
            set
            {
                if (_Sensor != value)
                {
                    displayUpdate();
                    _Sensor = value;
                }
            }
        }
        public bool _Stoper;
        public bool Stoper
        {
            get { return _Stoper; }
            set
            {
                if (_Stoper != value)
                {
                    displayUpdate();
                    _Stoper = value;
                }
            }
        }

        private int _DisplayIndex = 0;

        public int DisplayIndex
        {
            get { return _DisplayIndex; }
            set
            {
                if (_DisplayIndex != value)
                {
                    displayUpdate();
                    _DisplayIndex = value;
                }
            }
        }

        private void displayUpdate()
        {
            int t1 = _Sensor == true ? 1 : 0;
            int t2 = _Stoper == true ? 2 : 0;
            int t = t1 + t2;
            if (t == 0)//无感应传感器 和阻挡
            {
                pictureBox1.Image = imageList1.Images[0];
            }
            else if (t == 1)//有传感器
            {
                pictureBox1.Image = imageList1.Images[5];
            }
            else if (t == 2)//有阻挡
            {
                pictureBox1.Image = imageList1.Images[4];
            }
            else if (t == 3)
            {
                pictureBox1.Image = imageList1.Images[9];
            }
        }

        public int _Product = 0;
        public int product
        {
            set { _Product = value; }
            get { return _Product; }
        }
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            try
            {
                string str = this.Name; 
                Control ct = this.Parent;
                Point p = Control.MousePosition;
                MyfrmMessage frm = new MyfrmMessage(str, _Product,p);
                frm.Location = p;
                frm.ShowDialog();
            }
            catch (Exception ex)
            {
                LogExecute.WriteExceptionLog("DownStation", ex);
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            displayUpdate();
        }
    }
}