Exemple #1
0
 private void AddInfo(string msg)
 {
     if (this.textBox1.InvokeRequired)
     {
         SetTextCallback d = new SetTextCallback(AddInfo);
         this.Invoke(d, new object[] { msg });
     }
     else
     {
         string fMsg = String.Format("[{0}] {1} {2}", DateTime.Now.ToString("hh:mm:ss:ffff"), msg, Environment.NewLine);
         try
         {
             textBox1.AppendText(fMsg);
         } catch { };
     }
 }
Exemple #2
0
 private void SetLabelText(Label label, string text)
 {
     if (label.InvokeRequired)
     {
         try
         {
             SetTextCallback d = new SetTextCallback(SetLabelText);
             this.Invoke(d, new object[] { label, text });
         }catch (Exception e)
         {
             //TODO catch die shit
         }
     }
     else
     {
         label.Text = text;
     }
 }
Exemple #3
0
 private void SetText(string text)
 {
     if (this.textBox2.InvokeRequired)
     {
         SetTextCallback d = new SetTextCallback(SetText); // khởi tạo 1 delegate mới gọi đến SetText
         this.Invoke(d, new object[] { text });
     }
     else
     {
         data_receive += text;
     }
     if (data_receive.EndsWith("!"))
     {
         data_receive = data_receive.Substring(0, data_receive.Length - 1);
         //      if(isNumber(data_receive)==true)
         variable      = double.Parse(data_receive);
         textBox2.Text = data_receive;
         data_receive  = "";
     }
 }
Exemple #4
0
        private void SetText(string text)
        {
            // InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.

            if (this.textBox3.InvokeRequired)
            {
                SetTextCallback d = new SetTextCallback(SetText);
                this.Invoke(d, new object[] { text });
            }
            else
            {
                // this.textBox2.Clear();
                //text += "\r\n";
                //     this.label18.Text = "принято корректных сообщений " + Math.Round(((Convert.ToDouble(MessagesRecieved - CRCerrors)) * 100 / MessagesRecieved), 1).ToString() + " %";
                this.textBox3.AppendText(DateTime.Now.ToString() + " ---> ");
                this.textBox3.AppendText(text);//  = text;
                this.textBox3.AppendText("\r\n");
            }
        }
Exemple #5
0
 /// <summary>
 /// metodo auxiliar para actualizar interfaz de usuario.
 /// verifica si fue invocada por otro thread y de ser asi obtiene la firma del thread de de UX y se invoca a si mismo por medio del delegate
 /// actualiza grafica y labels necesarios
 /// </summary>
 /// <param name="text"></param>
 private void SetCpuIdle(string text)
 {
     if (this.label2.InvokeRequired)
     {   //se intento asignar desde thread distinto.
         //invocar por medio de delegate
         SetTextCallback d = new SetTextCallback(SetCpuIdle);
         if (!this.IsDisposed)
         {
             try
             {
                 this.Invoke(d, new object[] { text });
             }
             catch (Exception ex)
             {
                 //Console.WriteLine(ex);
                 //se intento invocar metodo en vista cuando esta ya habia sido recolectada por GC
             }
         }
     }
     else
     {
         this.label2.Text = text;
     }
 }
Exemple #6
0
        private void SetText(string name, string text)//委托修改UI控件
        {
            switch (name)
            {
            case "label99": { if (im.Form1.label99.InvokeRequired)
                              {
                                  SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                              }
                              else
                              {
                                  im.Form1.label99.Text = text;
                              } break; }

            case "comboBox1": { if (im.Form1.comboBox1.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.comboBox1.Text = text;
                                } break; }

            case "comboBox2": { if (im.Form1.comboBox2.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.comboBox2.Text = text;
                                } break; }

            case "comboBox3": { if (im.Form1.comboBox3.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.comboBox3.Text = text;
                                } break; }

            case "comboBox4": { if (im.Form1.comboBox4.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.comboBox4.Text = text;
                                } break; }

            case "comboBox5": { if (im.Form1.comboBox5.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.comboBox5.Text = text;
                                } break; }

            case "comboBox6": { if (im.Form1.comboBox6.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.comboBox6.Text = text;
                                } break; }

            case "comboBox7": { if (im.Form1.comboBox7.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.comboBox7.Text = text;
                                } break; }

            case "comboBox8": { if (im.Form1.comboBox8.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.comboBox8.Text = text;
                                } break; }

            case "textBox1": { if (im.Form1.textBox1.InvokeRequired)
                               {
                                   SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                               }
                               else
                               {
                                   im.Form1.textBox1.Text = text;
                               } break; }

            case "textBox2": { if (im.Form1.textBox2.InvokeRequired)
                               {
                                   SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                               }
                               else
                               {
                                   im.Form1.textBox2.Text = text;
                               } break; }

            case "textBox3": { if (im.Form1.textBox3.InvokeRequired)
                               {
                                   SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                               }
                               else
                               {
                                   im.Form1.textBox3.Text = text;
                               } break; }

            case "textBox4": { if (im.Form1.textBox4.InvokeRequired)
                               {
                                   SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                               }
                               else
                               {
                                   im.Form1.textBox4.Text = text;
                               } break; }

            //任务队列
            case "label3": { if (im.Form1.label3.InvokeRequired)
                             {
                                 SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                             }
                             else
                             {
                                 im.Form1.label3.Text = text;
                             } break; }

            case "label4": { if (im.Form1.label4.InvokeRequired)
                             {
                                 SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                             }
                             else
                             {
                                 im.Form1.label4.Text = text;
                             } break; }

            case "label5": { if (im.Form1.label5.InvokeRequired)
                             {
                                 SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                             }
                             else
                             {
                                 im.Form1.label5.Text = text;
                             } break; }

            case "label6": { if (im.Form1.label6.InvokeRequired)
                             {
                                 SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                             }
                             else
                             {
                                 im.Form1.label6.Text = text;
                             } break; }

            case "label7": { if (im.Form1.label7.InvokeRequired)
                             {
                                 SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                             }
                             else
                             {
                                 im.Form1.label7.Text = text;
                             } break; }

            //战斗任务的倒数
            case "textBox12": { if (im.Form1.textBox12.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox12.Text = text;
                                } break; }

            case "textBox14": { if (im.Form1.textBox14.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox14.Text = text;
                                } break; }

            case "textBox15": { if (im.Form1.textBox15.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox15.Text = text;
                                } break; }

            case "textBox17": { if (im.Form1.textBox17.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox17.Text = text;
                                } break; }

            case "textBox19": { if (im.Form1.textBox19.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox19.Text = text;
                                } break; }

            case "textBox6": { if (im.Form1.textBox6.InvokeRequired)
                               {
                                   SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                               }
                               else
                               {
                                   im.Form1.textBox6.Text = text;
                               } break; }

            case "textBox7": { if (im.Form1.textBox7.InvokeRequired)
                               {
                                   SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                               }
                               else
                               {
                                   im.Form1.textBox7.Text = text;
                               } break; }

            case "textBox8": { if (im.Form1.textBox8.InvokeRequired)
                               {
                                   SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                               }
                               else
                               {
                                   im.Form1.textBox8.Text = text;
                               } break; }

            case "textBox9": { if (im.Form1.textBox9.InvokeRequired)
                               {
                                   SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                               }
                               else
                               {
                                   im.Form1.textBox9.Text = text;
                               } break; }

            case "textBox10": { if (im.Form1.textBox10.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox10.Text = text;
                                } break; }

            case "textBox11": { if (im.Form1.textBox11.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox11.Text = text;
                                } break; }

            case "label12": { if (im.Form1.label12.InvokeRequired)
                              {
                                  SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                              }
                              else
                              {
                                  im.Form1.label12.Text = text;
                              } break; }

            case "label23": { if (im.Form1.label23.InvokeRequired)
                              {
                                  SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                              }
                              else
                              {
                                  im.Form1.label23.Text = text;
                              } break; }

            case "label24": { if (im.Form1.label24.InvokeRequired)
                              {
                                  SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                              }
                              else
                              {
                                  im.Form1.label24.Text = text;
                              } break; }

            case "label25": { if (im.Form1.label25.InvokeRequired)
                              {
                                  SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                              }
                              else
                              {
                                  im.Form1.label25.Text = text;
                              } break; }

            case "label26": { if (im.Form1.label26.InvokeRequired)
                              {
                                  SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                              }
                              else
                              {
                                  im.Form1.label26.Text = text;
                              } break; }

            case "textBox13": { if (im.Form1.textBox13.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox13.Text = text;
                                } break; }

            case "textBox16": { if (im.Form1.textBox16.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox16.Text = text;
                                } break; }

            case "textBox18": { if (im.Form1.textBox18.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox18.Text = text;
                                } break; }

            case "textBox5": { if (im.Form1.textBox5.InvokeRequired)
                               {
                                   SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                               }
                               else
                               {
                                   im.Form1.textBox5.Text = text;
                               } break; }

            case "textBox20": { if (im.Form1.textBox20.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox20.Text = text;
                                } break; }

            case "label13": { if (im.Form1.label13.InvokeRequired)
                              {
                                  SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                              }
                              else
                              {
                                  im.Form1.label13.Text = text;
                              } break; }

            case "textBox22": { if (im.Form1.textBox22.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox22.Text = text;
                                } break; }

            case "textBox23": { if (im.Form1.textBox23.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox23.Text = text;
                                } break; }

            case "textBox24": { if (im.Form1.textBox24.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox24.Text = text;
                                } break; }

            case "textBox25": { if (im.Form1.textBox25.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox25.Text = text;
                                } break; }

            case "textBox26": { if (im.Form1.textBox26.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox26.Text = text;
                                } break; }

            case "textBox27": { if (im.Form1.textBox27.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox27.Text = text;
                                } break; }

            case "label34": { if (im.Form1.label34.InvokeRequired)
                              {
                                  SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                              }
                              else
                              {
                                  im.Form1.label34.Text = text;
                              } break; }

            case "label35": { if (im.Form1.label35.InvokeRequired)
                              {
                                  SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                              }
                              else
                              {
                                  im.Form1.label35.Text = text;
                              } break; }

            case "label39": { if (im.Form1.label39.InvokeRequired)
                              {
                                  SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                              }
                              else
                              {
                                  im.Form1.label39.Text = text;
                              } break; }

            case "label40": { if (im.Form1.label40.InvokeRequired)
                              {
                                  SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                              }
                              else
                              {
                                  im.Form1.label40.Text = text;
                              } break; }


            case "textBox30": { if (im.Form1.textBox30.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox30.Text = text;
                                } break; }

            case "textBox31": { if (im.Form1.textBox31.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox31.Text = text;
                                } break; }

            case "textBox32": { if (im.Form1.textBox32.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox32.Text = text;
                                } break; }

            case "textBox33": { if (im.Form1.textBox33.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox33.Text = text;
                                } break; }

            case "textBox34": { if (im.Form1.textBox34.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox34.Text = text;
                                } break; }

            case "textBox35": { if (im.Form1.textBox35.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox35.Text = text;
                                } break; }

            case "textBox36": { if (im.Form1.textBox36.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox36.Text = text;
                                } break; }

            case "textBox37": { if (im.Form1.textBox37.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox37.Text = text;
                                } break; }

            case "textBox38": { if (im.Form1.textBox38.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox38.Text = text;
                                } break; }

            case "textBox39": { if (im.Form1.textBox39.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox39.Text = text;
                                } break; }

            case "textBox40": { if (im.Form1.textBox40.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox40.Text = text;
                                } break; }

            case "textBox41": { if (im.Form1.textBox41.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox41.Text = text;
                                } break; }

            case "textBox42": { if (im.Form1.textBox42.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox42.Text = text;
                                } break; }

            case "textBox43": { if (im.Form1.textBox43.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox43.Text = text;
                                } break; }

            case "textBox44": { if (im.Form1.textBox44.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox44.Text = text;
                                } break; }

            case "textBox45": { if (im.Form1.textBox45.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox45.Text = text;
                                } break; }

            case "textBox46": { if (im.Form1.textBox46.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox46.Text = text;
                                } break; }

            case "textBox47": { if (im.Form1.textBox47.InvokeRequired)
                                {
                                    SetTextCallback d = new SetTextCallback(SetText); im.Form1.Invoke(d, new object[] { name, text });
                                }
                                else
                                {
                                    im.Form1.textBox47.Text = text;
                                } break; }

            default:
                break;
            }
        }