Exemplo n.º 1
0
        private void FormServer_Load(object sender, EventArgs e)
        {
            AppendString = new AppendDelegate(AppendMethod);
            Addfriend    = new AddDelegate(AddMethod);
            Removefriend = new RemoveDelegate(RemoveMethod);
            //getting local IPv4 address
            List <string> listIP = getIP();

            if (listIP.Count == 0)
            {
                this.comboBoxIP.Items.Clear();
                this.comboBoxIP.Text = "Can not get IP address";
            }
            else if (listIP.Count == 1)
            {
                this.comboBoxIP.Items.Add(listIP[0]);
                this.comboBoxIP.SelectedIndex = 0;
            }
            else
            {
                foreach (string str in listIP)
                {
                    this.comboBoxIP.Items.Add(str);
                }
                this.comboBoxIP.Text = "Pls select or enter a IP address";
            }
            //default port
            textBoxServerPort.Text = "6000";
        }
Exemplo n.º 2
0
        //初始化加载
        private void FormServer_Load(object sender, EventArgs e)
        {
            //实例化委托对象,与委托方法关联
            AppendString = new AppendDelegate(AppendMethod);
            Addfriend = new AddDelegate(AddMethod);
            Removefriend = new RemoveDelegate(RemoveMethod);
            //获取本机IPv4地址
            List<string> listIP = getIP();
            if (listIP.Count == 0)
            {
                this.comboBoxIP.Items.Clear();
                this.comboBoxIP.Text = "未能获取IP!";
            }
            else if (listIP.Count == 1)
            {
                this.comboBoxIP.Items.Add(listIP[0]);
                this.comboBoxIP.SelectedIndex = 0;
            }
            else
            {
                foreach (string str in listIP)
                {
                    this.comboBoxIP.Items.Add(str);
                }
                this.comboBoxIP.Text = "请选择IP!";
            }
            //设置默认端口号
            textBoxServerPort.Text = "8899";

            buttonStop.Enabled = false;
        }
Exemplo n.º 3
0
 private void AppendOutput(string value)
 {
     if (InvokeRequired)
     {
         var appendDelegate = new AppendDelegate(AppendOutput);
         Invoke(appendDelegate, value);
     }
     else
     {
         Output.AppendText(value);
     }
 }
Exemplo n.º 4
0
        public override void Write(string message)
        {
            AppendDelegate append = new AppendDelegate(Append);

            if (output.InvokeRequired)
            {
                output.BeginInvoke(append, new object[] { message });
            }
            else
            {
                append(message);
            }
        }
Exemplo n.º 5
0
        private void rfidMain_Load(object sender, EventArgs e)
        {
            MaximizeBox = false;
            //实例化委托对象,与委托方法关联
            AppendString = new AppendDelegate(AppendMethod);
            Addfriend    = new AddDelegate(AddMethod);
            Removefriend = new RemoveDelegate(RemoveMethod);
            //获取本机IPv4地址
            List <string> listIP = getIP();

            if (listIP.Count == 0)
            {
                this.comboBoxIP.Items.Clear();
                this.comboBoxIP.Text = "未能获取IP!";
            }
            else if (listIP.Count == 1)
            {
                this.comboBoxIP.Items.Add(listIP[0]);
                this.comboBoxIP.SelectedIndex = 0;
            }
            else
            {
                foreach (string str in listIP)
                {
                    this.comboBoxIP.Items.Add(str);
                }
                this.comboBoxIP.Text = "请选择IP!";
            }
            //设置默认端口号
            textBoxServerPort.Text = "9600";
            System.Timers.Timer pTimer = new System.Timers.Timer(1000); //每隔1秒执行一次,没用winfrom自带的
            pTimer.Elapsed  += pTimer_Elapsed;                          //委托,要执行的方法
            pTimer.AutoReset = true;                                    //获取该定时器自动执行
            pTimer.Enabled   = true;                                    //这个一定要写,要不然定时器不会执行的
            Control.CheckForIllegalCrossThreadCalls = false;            //这个不太懂,有待研究

            startListen();                                              //开始监听
        }
Exemplo n.º 6
0
 public override void Write(string message)
 {
     AppendDelegate append = new AppendDelegate(Append);
     if (output.InvokeRequired)
     {
         output.BeginInvoke(append, new object[] { message });
     }
     else
     {
         append(message);
     }
 }