IOTextControl.cs 2.0 KB
using System;
using System.Drawing;
using System.Windows.Forms;

namespace UControl.UC
{
    public partial class IOTextControl : UserControl
    {
        public string IOName { get; set; }

        public int IOValue { get; set; }
        public bool CanClick { get; set; } = false;
        public IOTextControl()
        {
            InitializeComponent();
        }
        public IOTextControl(string ioName, string name, int widht = 220, int height = 26, int ioValue = -1, bool canClick = false, int tabIndex = 0)
        {
            InitializeComponent();
            IOName = ioName;
            IOValue = IOValue;
            CanClick = canClick;
            Name = "IO_" + name;
            Size = new Size(widht, height);
            TabIndex = tabIndex;
        }
        public void ShowData()
        {
            this.Invoke(new Action(() => {
                label1.Text = IOName;
                if (IOValue == 0)
                {
                    picBoxState.Image = UIControl.Properties.Resource.gray;
                }
                else if (IOValue == 1)
                {
                    picBoxState.Image = UIControl.Properties.Resource.green;
                }
                else
                {
                    picBoxState.Image = UIControl.Properties.Resource.gray;
                }
            }));
        }

        private void label1_DoubleClick(object sender, EventArgs e)
        {
            this.OnDoubleClick(e);
        }

        private void label1_Click(object sender, EventArgs e)
        {

            this.OnClick(e);
        }

        private void IOTextControl_Load(object sender, EventArgs e)
        {
            ShowData();
        }

        private void picBoxState_Click(object sender, EventArgs e)
        {
            this.OnClick(e);
        }

        private void picBoxState_DoubleClick(object sender, EventArgs e)
        {
            this.OnDoubleClick(e);
            ImageList list = new ImageList();
            list.Images.Add(UIControl.Properties.Resource.gray);
        }
    }
}