private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { try { TreeNode tn = e.Node; if (tn != null) { SlaveMachine sm = (SlaveMachine)tn.Tag; textBox1.Tag = sm.ip; textBox1.Text = sm.getSendReceive(); textBox3.Text = sm.ip; if (sm.Online) { textBox6.Text = "" + sm.CommunicationPort; textBox7.Text = "1642"; } } } catch (Exception err) { MessageBox.Show("" + err.Message); } }
private void button1_Click(object sender, EventArgs e) { try { int count = Int32.Parse(comboBox1.Text); if (count > 250 || count <= 0) { MessageBox.Show("请输入合理的值"); return; } treeView1.Nodes.Clear(); sms = new SlaveMachine[count + 1]; SlaveMachine sm = new SlaveMachine(); sm.ip = "所有设备"; sms[0] = sm; for (int i = 1; i <= count; i++) { SlaveMachine sm2 = new SlaveMachine(); sm2.ip = ipd + i; sms[i] = sm2; } for (int i = 0; i <= count; i++) { TreeNode tn = new TreeNode(); tn.Text = sms[i].ip; tn.Tag = sms[i]; treeView1.Nodes.Add(tn); } } catch (Exception err) { MessageBox.Show("请输入正确的值");; } }