Пример #1
0
        private async void button1_Click(object sender, EventArgs e)
        {
            if (!int.TryParse(textBox2.Text, out int port))
            {
                MessageBox.Show("端口输入格式不正确!");
                return;
            }

            YRC1000Tcp?.ConnectClose( );
            YRC1000Tcp = new YRC1000TcpNet(textBox1.Text, port);

            try
            {
                OperateResult connect = await YRC1000Tcp.ConnectServerAsync( );

                if (connect.IsSuccess)
                {
                    MessageBox.Show("连接成功!");
                    button2.Enabled = true;
                    button1.Enabled = false;
                    panel2.Enabled  = true;
                }
                else
                {
                    MessageBox.Show("连接失败!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }