using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace _8K_do { public partial class Form1 : Form { CheckBox[] cbArr = new CheckBox[32]; public Form1() { InitializeComponent(); for (int i = 0; i < 32; i++) { cbArr[i] = new CheckBox(); this.Controls.Add(cbArr[i]); } } private void Form1_Load(object sender, EventArgs e) { cbbSlot.SelectedIndex = 0; cbbChannel.SelectedIndex = 0; int total_ch = int.Parse(cbbChannel.Items[cbbChannel.SelectedIndex].ToString()); printCheckBoxs(total_ch); for (int i = 0; i < 32; i++) { cbArr[i].CheckStateChanged += new System.EventHandler(this.checkBox_CheckStateChanged); } } private void printCheckBoxs(int channel) { int x = 20; int y = 120; for (int i = 0; i < channel; i++) { cbArr[i].Location = new Point(x + 80 * (i % 8), y + 40 * (i / 8)); cbArr[i].Size = new Size(80, 20); cbArr[i].Text = "DO_" + i.ToString("00"); cbArr[i].Visible = true; } for (int j = channel; j < 32; j++) { cbArr[j].Visible = false; } } private void checkBox_CheckStateChanged(object sender, EventArgs e) { uint DO_value = 0; uint one = 1; for (int i = 0; i < 32; i++) { if ((cbArr[i].Visible == true) && (cbArr[i].Checked == true)) { DO_value += one << (int.Parse(i.ToString())); } } textBox1.Text = DO_value.ToString(); } private void cbbChannel_SelectedIndexChanged(object sender, EventArgs e) { int total_ch = int.Parse(cbbChannel.Items[cbbChannel.SelectedIndex].ToString()); printCheckBoxs(total_ch); button3_Click(sender, e); //clear all } private void button1_Click(object sender, EventArgs e) { int slot = cbbSlot.SelectedIndex + 1; int total_ch = int.Parse(cbbChannel.Items[cbbChannel.SelectedIndex].ToString()); uint DO_Value = uint.Parse(textBox1.Text); PACNET.PAC_IO.WriteDO((IntPtr)null, slot, total_ch, DO_Value); } private void button2_Click(object sender, EventArgs e) { //select all for (int i = 0; i < 32; i++) { if (cbArr[i].Visible == true) { cbArr[i].Checked = true; } } } private void button3_Click(object sender, EventArgs e) { //clear all for (int i = 0; i < 32; i++) { if (cbArr[i].Visible == true) { cbArr[i].Checked = false; } } } private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyData == Keys.Enter) { uint DO_value = uint.Parse(textBox1.Text); for (int i = 0; i < 32; i++) { if (1 == (1 & (DO_value >> i))) { cbArr[i].Checked = true; } else { cbArr[i].Checked = false; } } } } } }