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; namespace Mesnac.Controls.Sulf { [ToolboxBitmap(typeof(TextBox))] public partial class IOControl : UserControl { public IOControl() { InitializeComponent(); //this.B1. = Color.Yellow; } #region 属性 private string _iOName; /// /// IO名称 /// public string IOName { get { return this.button1.Text; } set { _iOName = value; this.button1.Text = _iOName; } } private string _iOName1; /// /// IO1名称 /// public string IOName1 { get { return this.B1.Text; } set { _iOName1 = value; this.B1.Text = _iOName1; } } private string _iOName2; /// /// IO1名称 /// public string IOName2 { get { return _iOName2; } set { _iOName2 = value; this.B2.Text = _iOName2; } } private string _iOName3; /// /// IO3名称 /// public string IOName3 { get { return _iOName3; } set { _iOName3 = value; this.B3.Text = _iOName3; } } private string _iOName4; /// /// IO4名称 /// public string IOName4 { get { return _iOName4; } set { _iOName4 = value; this.B4.Text = _iOName4; } } private string _iOName5; /// /// IO5名称 /// public string IOName5 { get { return _iOName5; } set { _iOName5 = value; this.B5.Text = _iOName5; } } private string _iOName6; /// /// IO6名称 /// public string IOName6 { get { return _iOName6; } set { _iOName6 = value; this.B6.Text = _iOName6; } } private string _iOName7; /// /// IO7名称 /// public string IOName7 { get { return _iOName7; } set { _iOName7 = value; this.B7.Text = _iOName7; } } private string _iOName8; /// /// IO8名称 /// public string IOName8 { get { return _iOName8; } set { _iOName8 = value; this.B8.Text = _iOName8; } } private string _iOName9; /// /// IO9名称 /// public string IOName9 { get { return _iOName9; } set { _iOName9 = value; this.B9.Text = _iOName9; } } private string _iOName10; /// /// IO10名称 /// public string IOName10 { get { return _iOName10; } set { _iOName10 = value; this.B10.Text = _iOName10; } } private string _iOName11; /// /// IO11名称 /// public string IOName11 { get { return _iOName11; } set { _iOName11 = value; this.B11.Text = _iOName11; } } private string _iOName12; /// /// IO12名称 /// public string IOName12 { get { return _iOName12; } set { _iOName12 = value; this.B12.Text = _iOName12; } } private string _iOName13; /// /// IO13名称 /// public string IOName13 { get { return _iOName13; } set { _iOName13 = value; this.B13.Text = _iOName13; } } private string _iOName14; /// /// IO14名称 /// public string IOName14 { get { return _iOName14; } set { _iOName14 = value; this.B14.Text = _iOName14; } } private string _iOName15; /// /// IO15名称 /// public string IOName15 { get { return _iOName15; } set { _iOName15 = value; this.B15.Text = _iOName15; } } private string _iOName16; /// /// IO16名称 /// public string IOName16 { get { return _iOName16; } set { _iOName16 = value; this.B16.Text = _iOName16; } } private bool _fontleft; public bool Fontleft { get { return _fontleft; } set { _fontleft = value; if (value) { this.B1.TextAlign = ContentAlignment.MiddleLeft; this.B2.TextAlign = ContentAlignment.MiddleLeft; this.B3.TextAlign = ContentAlignment.MiddleLeft; this.B4.TextAlign = ContentAlignment.MiddleLeft; this.B5.TextAlign = ContentAlignment.MiddleLeft; this.B6.TextAlign = ContentAlignment.MiddleLeft; this.B7.TextAlign = ContentAlignment.MiddleLeft; this.B8.TextAlign = ContentAlignment.MiddleLeft; this.B9.TextAlign = ContentAlignment.MiddleLeft; this.B10.TextAlign = ContentAlignment.MiddleLeft; this.B11.TextAlign = ContentAlignment.MiddleLeft; this.B12.TextAlign = ContentAlignment.MiddleLeft; this.B13.TextAlign = ContentAlignment.MiddleLeft; this.B14.TextAlign = ContentAlignment.MiddleLeft; this.B15.TextAlign = ContentAlignment.MiddleLeft; this.B16.TextAlign = ContentAlignment.MiddleLeft; } } } private bool _fontColor; public bool FontColor { get { return _fontColor; } set { _fontColor = value; if (_fontColor) { this.B1.ForeColor = Color.Yellow; this.B2.ForeColor = Color.Yellow; this.B3.ForeColor = Color.Yellow; this.B4.ForeColor = Color.Yellow; this.B5.ForeColor = Color.Yellow; this.B6.ForeColor = Color.Yellow; this.B7.ForeColor = Color.Yellow; this.B8.ForeColor = Color.Yellow; this.B9.ForeColor = Color.Yellow; this.B10.ForeColor = Color.Yellow; this.B11.ForeColor = Color.Yellow; this.B12.ForeColor = Color.Yellow; this.B13.ForeColor = Color.Yellow; this.B14.ForeColor = Color.Yellow; this.B15.ForeColor = Color.Yellow; this.B16.ForeColor = Color.Yellow; } } } #endregion #region 动画 private string _equipName; public string EquipName { get { return _equipName; } set { _equipName = value; } } public string EquipValue { set { if (!string.IsNullOrEmpty(value)) { string retValue = string.Empty; int data = 0; int.TryParse(value, out data); int[] datas = new int[16]; //int[] datas = ParseBinaryValue(data, 16); string Dec = data.ToString(); //string bv = string.Empty; //for (int j = 0; j < Dec.Length; j++) //{ // int[] bitValue = ParseBinaryValue(Convert.ToInt32(Dec.Substring(Dec.Length - 1 - j, 1)), 4); // for (int i = 0; i < 4; i++) // { // bv += bitValue[i]; // } // retValue = bv + retValue; // bv = string.Empty; //} //string temp = retValue.PadLeft(16, '0'); int[] bitValue = ParseBinaryValue(Convert.ToInt32(Dec), 16); //if (temp.Length == 16) //{ // for (int i = 0; i <16; i++) // { // int j = 0; // int.TryParse(temp.Substring(i, 1),out j); // datas[i] = j; // } //} B1.BackColor = bitValue[15] == 0 ? Color.Black : Color.Green; B2.BackColor = bitValue[14] == 0 ? Color.Black : Color.Green; B3.BackColor = bitValue[13] == 0 ? Color.Black : Color.Green; B4.BackColor = bitValue[12] == 0 ? Color.Black : Color.Green; B5.BackColor = bitValue[11] == 0 ? Color.Black : Color.Green; B6.BackColor = bitValue[10] == 0 ? Color.Black : Color.Green; B7.BackColor = bitValue[9] == 0 ? Color.Black : Color.Green; B8.BackColor = bitValue[8] == 0 ? Color.Black : Color.Green; B9.BackColor = bitValue[7] == 0 ? Color.Black : Color.Green; B10.BackColor = bitValue[6] == 0 ? Color.Black : Color.Green; B11.BackColor = bitValue[5] == 0 ? Color.Black : Color.Green; B12.BackColor = bitValue[4] == 0 ? Color.Black : Color.Green; B13.BackColor = bitValue[3] == 0 ? Color.Black : Color.Green; B14.BackColor = bitValue[2] == 0 ? Color.Black : Color.Green; B15.BackColor = bitValue[1] == 0 ? Color.Black : Color.Green; B16.BackColor = bitValue[0] == 0 ? Color.Black : Color.Green; } } } #endregion /// /// 解析二进制位 /// /// 要解析的变量 /// 解析的长度 /// 返回解析的二进制值数组 public int[] ParseBinaryValue(int x, int len) { int[] result = new int[len]; int b = 1; for (int i = len - 1; i >= 0; i--) { result[i] = (x & b) == 0 ? 0 : 1; b = b << 1; } return result; } } }