private void btn_assign_Click(object sender, EventArgs e)
        {
            if (m_start)
            {
                m_start = false;
                netfinder.Stop();
                btn_start.BackColor = Color.FromArgb(0, 192, 0);
                btn_start.Text = "Search";
            }

            if (netfinder.Operation != RecvOperation.IDLE)
            {
                MessageBox.Show("Please stop searching device first.");
                return;
            }

            using (AssignForm assign = new AssignForm())
            {
                //assign.CS203IP = lv_device.Items[lv_device.SelectedIndices[0]].SubItems[2].Text;
                byte[] ipb = lv_device.devicelist[lv_device.SelectedIndex].ip.Address;
                assign.CS203IP = String.Format("{0}.{1}.{2}.{3}", ipb[0], ipb[1], ipb[2], ipb[3]);
                assign.DeviceName = lv_device.devicelist[lv_device.SelectedIndex].device_name;
                assign.Timeout = lv_device.devicelist[lv_device.SelectedIndex].tcptimeout;
                assign.DHCP = lv_device.devicelist[lv_device.SelectedIndex].DHCP;
                if (assign.ShowDialog() == DialogResult.OK)
                {
                    string[] ip = assign.CS203IP.Split(new char[] { '.' });
                    if (ip != null && ip.Length == 4)
                    {
                        netfinder.AssignDevice(
                            lv_device.devicelist[lv_device.SelectedIndex].mac.Address, 
                            new byte[] { byte.Parse(ip[0]), byte.Parse(ip[1]), byte.Parse(ip[2]), byte.Parse(ip[3]) },
                            assign.DeviceName, 
                            assign.Timeout,
                            assign.DHCP);
                    }
                }
            }
        }
        private void btn_assign_Click(object sender, EventArgs e)
        {
            if (m_start)
            {
                m_start = false;
                netfinder.Stop();
                btn_start.BackColor = Color.FromArgb(0, 192, 0);
                btn_start.Text      = "Search";
            }

            if (netfinder.Operation != RecvOperation.IDLE)
            {
                MessageBox.Show("Please stop searching device first.");
                return;
            }

            using (AssignForm assign = new AssignForm())
            {
                //assign.CS203IP = lv_device.Items[lv_device.SelectedIndices[0]].SubItems[2].Text;
                byte[] ipb  = lv_device.devicelist[lv_device.SelectedIndex].IPAddress.Address;
                byte[] tsIP = lv_device.devicelist[lv_device.SelectedIndex].TrustedServer.Address;
                assign.CS203IP       = String.Format("{0}.{1}.{2}.{3}", ipb[0], ipb[1], ipb[2], ipb[3]);
                assign.DeviceName    = lv_device.devicelist[lv_device.SelectedIndex].DeviceName;
                assign.DHCPRetry     = lv_device.devicelist[lv_device.SelectedIndex].DHCPRetry;
                assign.DHCPEnable    = lv_device.devicelist[lv_device.SelectedIndex].DHCPEnabled;
                assign.TrustedServer = String.Format("{0}.{1}.{2}.{3}", tsIP[0], tsIP[1], tsIP[2], tsIP[3]);
                assign.TrustedEnable = lv_device.devicelist[lv_device.SelectedIndex].TrustedServerEnabled;
                assign.Subnet        = lv_device.devicelist[lv_device.SelectedIndex].SubnetMask;
                assign.Gateway       = lv_device.devicelist[lv_device.SelectedIndex].Gateway;
                if (lv_device.devicelist[lv_device.SelectedIndex].GatewayCheckResetMode < 0)
                {
                    assign.checkBox_GatewayCheckResetMode.Visible = false;
                }
                else
                {
                    assign.checkBox_GatewayCheckResetMode.Visible = true;
                    if (lv_device.devicelist[lv_device.SelectedIndex].GatewayCheckResetMode == 1)
                    {
                        assign.checkBox_GatewayCheckResetMode.Checked = true;
                    }
                    else
                    {
                        assign.checkBox_GatewayCheckResetMode.Checked = false;
                    }
                }

                if (assign.ShowDialog() == DialogResult.OK)
                {
                    string[] ip      = assign.CS203IP.Split(new char[] { '.' });
                    string[] ts_ip   = assign.TrustedServer.Split(new char[] { '.' });
                    string[] subnet  = assign.Subnet.Split(new char[] { '.' });
                    string[] gateway = assign.Gateway.Split(new char[] { '.' });
                    if (ip != null && ip.Length == 4)
                    {
                        netfinder.AssignDevice(
                            lv_device.devicelist[lv_device.SelectedIndex].MACAddress.Address,
                            new byte[] { byte.Parse(ip[0]), byte.Parse(ip[1]), byte.Parse(ip[2]), byte.Parse(ip[3]) },
                            assign.DeviceName,
                            assign.DHCPRetry,
                            assign.DHCPEnable,
                            new byte[] { byte.Parse(ts_ip[0]), byte.Parse(ts_ip[1]), byte.Parse(ts_ip[2]), byte.Parse(ts_ip[3]) },
                            assign.TrustedEnable,
                            new byte[] { byte.Parse(subnet[0]), byte.Parse(subnet[1]), byte.Parse(subnet[2]), byte.Parse(subnet[3]) },
                            new byte[] { byte.Parse(gateway[0]), byte.Parse(gateway[1]), byte.Parse(gateway[2]), byte.Parse(gateway[3]) },
                            ((lv_device.devicelist[lv_device.SelectedIndex].GatewayCheckResetMode < 0) ? -1 : assign.checkBox_GatewayCheckResetMode.Checked ? 1 : 0)
                            );
                    }
                }
            }
        }