Example #1
0
        /// <summary>
        /// This method is responsible for displaying recieved data in textBox.
        /// (ThreadSafety!)
        /// </summary>
        /// <param name="msg"></param>
        public void addDataToDisplay(String msg)
        {
            if (this.textBox1.InvokeRequired)
            {
                SetTextCallBack d = new SetTextCallBack(addDataToDisplay);
                try
                {
                    this.Invoke(d, new object[] { msg });
                }
                catch (Exception e)
                {
                    Form1.logException("Exception while adding to Console.textBox1 msg = " + e.Message);
                }
            }
            else
            {
                try
                {
                    textBox1.Text = msg;

                    if (m_autoCheck)
                    {
                        m_parentForm.sendDataViaPort("temp!");
                    }

                }
                catch (Exception e)
                {
                    Form1.logException("Exception while adding to Console.textBox1 msg = " + e.Message);
                }
            }
        }
Example #2
0
        public void SetText(string text)
        {
            if (this.console.InvokeRequired)
            {
                SetTextCallBack stcb = new SetTextCallBack(SetText);
                this.Invoke(stcb, new object[] { text });
            }
            else
            {
                if (!string.IsNullOrEmpty(text))
                {
                    this.console.AppendText(text + "\r\n");
                }

                bool lockScrollBar = this.checkBox1.Checked;

                if (!lockScrollBar)
                {
                    console.SelectionStart = console.Text.Length;
                    console.ScrollToCaret();
                }
                else
                {
                    console.SelectionStart = mCurrentIndex;
                    console.ScrollToCaret();
                }
            }
        }
Example #3
0
 public void SetText(string text)
 {
     if (text == "")
     {
         if (textBox1.InvokeRequired)
         {
             SetTextCallBack st = new SetTextCallBack(SetText);
             this.Invoke(st, new object[] { text });
         }
         else
         {
             textBox1.Text = "\n";
         }
     }
     else
     {
         if (textBox1.InvokeRequired)
         {
             SetTextCallBack st = new SetTextCallBack(SetText);
             this.Invoke(st, new object[] { text });
         }
         else
         {
             textBox1.Text = text + "\n";
         }
     }
 }
Example #4
0
 public static void AppendTextByAsync(this RichTextBox rtBox, string text, Color color, bool addNewLine = true)
 {
     try
     {
         if (rtBox.IsDisposed)
         {
             return;
         }
         if (rtBox.InvokeRequired)
         {
             SetTextCallBack stcb = new SetTextCallBack(AppendTextColorful);
             rtBox.Invoke(stcb, new object[] { rtBox, text, color, addNewLine });
         }
         else
         {
             if (addNewLine)
             {
                 text += Environment.NewLine;
             }
             rtBox.SelectionStart  = rtBox.TextLength;
             rtBox.SelectionLength = 0;
             rtBox.SelectionColor  = color;
             rtBox.AppendText(text);
             rtBox.SelectionColor = rtBox.ForeColor;
             rtBox.SelectionStart = rtBox.Text.Length; //Set the current caret position at the end
             rtBox.ScrollToCaret();                    //Now scroll it automatically
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.StackTrace);
     }
 }
Example #5
0
        public FrmProgress()
        {
            InitializeComponent();

            _setProgressText  = SetProgressBarText;
            _setProgressValue = SetProgressBarValue;
        }
Example #6
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            try
            {
                //实例一个socket对象
                client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                IPAddress ip   = IPAddress.Parse(txtIp.Text);
                int       port = Convert.ToInt32(txtPort.Text);

                IPEndPoint ie = new IPEndPoint(ip, port);
                client.Connect(ie);


                setCallBack     = setValue;
                receiveCallBack = receiveData;

                this.rtxtRecv.Invoke(setCallBack, "已经成功连接到服务器!");

                thReceive = new Thread(new ThreadStart(Receive));
                thReceive.IsBackground = true;
                thReceive.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show("连接服务器时出错:" + ex.ToString());
            }
        }
Example #7
0
 /// <summary>
 /// This method is responsible for displaying recieved data in textBox.
 /// (ThreadSafety!)
 /// </summary>
 /// <param name="msg"></param>
 public void addDataToDisplay(String msg)
 {
     if (this.textBox1.InvokeRequired)
     {
         SetTextCallBack d = new SetTextCallBack(addDataToDisplay);
         try
         {
             this.Invoke(d, new object[] { msg });
         }
         catch (Exception e)
         {
             Form1.logException("Exception while adding to Console.textBox1 msg = " + e.Message);
         }
     }
     else
     {
         try
         {
             textBox1.AppendText(msg+"\n");
         }
         catch (Exception e)
         {
             Form1.logException("Exception while adding to Console.textBox1 msg = " + e.Message);
         }
     }
 }
Example #8
0
        private void button_Connect_Click(object sender, EventArgs e)
        {
            try
            {
                socketSend = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                IPAddress ip = IPAddress.Parse(this.textBox_IP.Text.Trim());
                socketSend.Connect(ip, Convert.ToInt32(this.textBox_Port.Text.Trim()));

                //实例化回调
                setCallBack     = new SetTextCallBack(SetValue);
                receiveCallBack = new ReceiveMsgCallBack(SetValue);
                this.richTextBox_Log.Invoke(setCallBack, "连接成功");


                //开启一个新的线程不停的接收服务器发送消息的线程
                threadReceive = new Thread(new ThreadStart(Receive));

                //设置为后台线程
                threadReceive.IsBackground = true;
                threadReceive.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show("连接服务端出错:" + ex.ToString());
            }
        }
Example #9
0
        /// <summary>
        /// 连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void connect_Click(object sender, EventArgs e)
        {
            try
            {
                //  IPHostEntry hostInfo = Dns.GetHostEntry("47.100.46.2");
                //     IPAddress ipAddress = hostInfo.AddressList[0];

                //   txt_IP = "superpao.aiweber.com/socket";
                //   txt_Port = "80";
                socketSend = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                IPAddress ip = IPAddress.Parse("47.100.46.2");
                socketSend.Connect(ip, 2120);
                //实例化回调
                setCallBack     = new SetTextCallBack(SetValue);
                receiveCallBack = new ReceiveMsgCallBack(SetValue);
                // this.Label.Invoke(setCallBack, "连接成功");

                this.label1.Text = "receive  successful" + receiveCallBack.ToString();
                //    MessageBox.Show("lianjieco:" + setCallBack.ToString());
                //开启一个新的线程不停的接收服务器发送消息的线程
                threadReceive = new Thread(new ThreadStart(Receive));
                //设置为后台线程
                threadReceive.IsBackground = false;
                threadReceive.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show("连接服务端出错:" + ex.ToString());
            }
        }
Example #10
0
 private void setText(string text)
 {
     //try
     {
         if (this.textBox1.InvokeRequired)
         {
             while (!this.textBox1.IsHandleCreated)
             {
                 if (this.textBox1.Disposing || this.textBox1.IsDisposed)
                 {
                     return;
                 }
             }
             SetTextCallBack d = new SetTextCallBack(setText);
             this.textBox1.Invoke(d, new object[] { text });
         }
         else
         {
             this.textBox1.Text = text;
         }
     }
     //catch (System.Exception ex)
     //{
     //	string str = ex.Message;
     //}
 }
Example #11
0
File: Graph.cs Project: altanis/AVR
        /// <summary>
        /// Adds text to text box and to graph.
        /// </summary>
        /// <param name="msg"></param>
        public void addDataToDisplay(String msg)
        {
            if (this.textBox1.InvokeRequired)
            {
                SetTextCallBack d = new SetTextCallBack(addDataToDisplay);
                try
                {
                    this.Invoke(d, new object[] { msg });
                }
                catch (Exception e)
                {
                    Form1.logException("Exception while adding to Console.textBox1 msg = " + e.Message);
                }
            }
            else
            {
                try
                {
                    textBox1.Text = msg;
                    double x, y1;
                    DateTime dt = DateTime.Now;
                    x = new XDate(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second);

                    msg = msg.Trim();

                    //parsing to double bug fix
                    int firstPart = 0;
                    int lastPart = 0;
                    if (msg.Length == 4)
                    {
                        firstPart = Int32.Parse(msg.Substring(0, 2));
                        lastPart = Int32.Parse(msg.Substring(3, 1));
                    }
                    else if (msg.Length == 3)
                    {
                        firstPart = Int32.Parse(msg.Substring(0, 1));
                        lastPart = Int32.Parse(msg.Substring(2, 1));
                    }

                    y1 = firstPart + (0.1 * lastPart);

                    m_pairList.Add(x, y1);

                    m_pane.AxisChange();
                    zedGraphControl1.AxisChange();
                    zedGraphControl1.Refresh();

                    if (m_check)
                    {
                        m_parentForm.sendDataViaPort("temp!");
                    }

                }
                catch (Exception e)
                {
                    Form1.logException("Exception while adding to Console.textBox1 msg = " + e.Message);
                }
            }
        }
Example #12
0
        //EventLog myLog = new EventLog();

        public FrmProgress()
        {
            InitializeComponent();

            _setProgressText  = SetProgressBarText;
            _setProgressValue = SetProgressBarValue;

            //myLog.Source = "ForLABLog";
        }
Example #13
0
        //EventLog myLog = new EventLog();
        public FrmProgress()
        {
            InitializeComponent();

            _setProgressText = SetProgressBarText;
            _setProgressValue = SetProgressBarValue;

            //myLog.Source = "ForLABLog";
        }
Example #14
0
        public FrmProgress(MorbidityForecast forecast, InventoryAssumption invAssumption)
        {
            //this._morbidityForm = morbidityForm;
            this._forecast = forecast;
            this._invAssumption = invAssumption;

            InitializeComponent();

            _setProgressText = new SetTextCallBack(SetProgressBarText);
            _setProgressValue = new SetProgressBarCallBack(SetProgressBarValue);
        }
Example #15
0
        public FrmProgress(MorbidityForecast forecast, InventoryAssumption invAssumption)
        {
            //this._morbidityForm = morbidityForm;
            this._forecast      = forecast;
            this._invAssumption = invAssumption;

            InitializeComponent();

            _setProgressText  = new SetTextCallBack(SetProgressBarText);
            _setProgressValue = new SetProgressBarCallBack(SetProgressBarValue);
        }
Example #16
0
 private void SetText(string text)
 {
     if (textBox1.InvokeRequired)
     {
         SetTextCallBack d = new SetTextCallBack(SetText);
         this.Invoke(d, new object[] { text });
     }
     else
     {
         this.textBox1.Text = text;
     }
 }
Example #17
0
 // This method demonstrates a pattern for making thread-safe
 // calls on a Windows Forms control.
 //
 // If the calling thread is different from the thread that
 // created the TextBox control, this method creates a
 // SetTextCallback and calls itself asynchronously using the
 // Invoke method.
 //
 // If the calling thread is the same as the thread that created
 // the TextBox control, the Text property is set directly.
 private void SetText(String stuff)
 {
     if (this.pingLabel.InvokeRequired)
     {
         SetTextCallBack s = new SetTextCallBack(SetText);
         this.Invoke(s, new object[] { stuff });
     }
     else
     {
         pingLabel.Text = stuff;
     }
 }
Example #18
0
 private void setrcvback(String txt)
 {
     if (this.btn_num.InvokeRequired)
     {
         SetTextCallBack d = new SetTextCallBack(setrcvback);
         this.Invoke(d, new object[] { txt });
     }
     else
     {
         btn_num.Text = txt;
     }
 }
Example #19
0
 public void ChangeButtonText(String txt)
 {
     if (outputBox.InvokeRequired)
     {
         SetTextCallBack d = new SetTextCallBack(ChangeButtonText);
         this.Invoke(d, new object[] { txt });
     }
     else
     {
         this.button1.Text = txt;
     }
 }
Example #20
0
 private void SetText(string text)
 {
     if (this.txtLogInfo.InvokeRequired)
     {
         SetTextCallBack d = new SetTextCallBack(SetText);
         this.Invoke(d, new object[] { text });
     }
     else
     {
         this.txtLogInfo.Text = text;
     }
 }
Example #21
0
 public void Populator(string txt)
 {
     if (this.InvokeRequired)
     {
         SetTextCallBack txtCall = new SetTextCallBack(Populator);
         this.Invoke(txtCall, txt);
     }
     else
     {
         cb_serv.Items.Add(txt);
     }
 }
Example #22
0
 public void SetTextchat(string txt)
 {
     if (this.InvokeRequired)
     {
         SetTextCallBack txtCall = new SetTextCallBack(SetTextchat);
         this.Invoke(txtCall, txt);
     }
     else
     {
         rc_chat.Text += txt + Environment.NewLine;
     }
 }
Example #23
0
 public void TitleSetup(string txt)
 {
     if (this.InvokeRequired)
     {
         SetTextCallBack txtCall = new SetTextCallBack(TitleSetup);
         this.Invoke(txtCall, txt);
     }
     else
     {
         this.Text = txt;
     }
 }
Example #24
0
 private void SetTip(string tip)
 {
     if (lbTip.InvokeRequired)
     {
         SetTextCallBack sb = new SetTextCallBack(SetTip);
         this.Invoke(sb, new object[] { tip });
     }
     else
     {
         lbTip.Text = tip;
     }
 }
Example #25
0
 private void SetAccumTask(string count)
 {
     if (lbAccumTask.InvokeRequired)
     {
         SetTextCallBack sb = new SetTextCallBack(SetAccumTask);
         this.Invoke(sb, new object[] { count });
     }
     else
     {
         lbAccumTask.Text = count;
     }
 }
Example #26
0
 public void SetText(string txt)
 {
     if (this.InvokeRequired)
     {
         SetTextCallBack txtCall = new SetTextCallBack(SetText);
         this.Invoke(txtCall, txt);
     }
     else
     {
         tb_logcommand.Text += " " + txt + Environment.NewLine;
     }
 }
Example #27
0
 private void SetlbHead(string head)
 {
     if (lbhead.InvokeRequired)
     {
         SetTextCallBack sb = new SetTextCallBack(SetlbHead);
         this.Invoke(sb, new object[] { head });
     }
     else
     {
         lbhead.Text = head;
     }
 }
 //handles requests coming for other threads, requiring invoke.
 public void displayIncomingText(string msg)
 {
     if (textIncoming.InvokeRequired)
     {
         SetTextCallBack d = new SetTextCallBack(displayIncomingText);
         this.Invoke(d, new object[] { msg });
     }
     else
     {
         this.textIncoming.AppendText(msg + newline);
     }
 }
Example #29
0
 private void SetText(string tekst)
 {
     if (textBox1.InvokeRequired)
     {
         SetTextCallBack f = new SetTextCallBack(SetText);
         this.Invoke(f, new object[] { tekst });
     }
     else
     {
         this.textBox1.Text = tekst;
     }
 }
Example #30
0
 private void SetText(string text)
 {
     if (this.txt_Recevicecontext.InvokeRequired)
     {
         SetTextCallBack stcb = new SetTextCallBack(SetText);
         this.Invoke(stcb, new object[] { text });
     }
     else
     {
         this.txt_Recevicecontext.Text = text;
     }
 }
Example #31
0
 private void SetText(string tekst)
 {
     if (listBox1.InvokeRequired)
     {
         SetTextCallBack f = new SetTextCallBack(SetText);
         this.Invoke(f, new object[] { tekst });
     }
     else
     {
         this.listBox1.Items.Add(tekst);
     }
 }
Example #32
0
 private void SetLoaclText(string text)
 {
     if (WebNowTime.InvokeRequired)
     {
         SetTextCallBack stcb = SetLoaclText;
         Invoke(stcb, text);
     }
     else
     {
         LocalNowTime.Text = text;
     }
 }
Example #33
0
 private void SetText5(string text)
 {
     if (this.textBox5.InvokeRequired)
     {
         SetTextCallBack stcb = new SetTextCallBack(SetText5);
         this.Invoke(stcb, new object[] { text });
     }
     else
     {
         this.textBox5.Text = text;
     }
 }
Example #34
0
 void SetResultText(string text)
 {
     if (this.labelResult.InvokeRequired)
     {
         SetTextCallBack call = new SetTextCallBack(SetResultText); // 来自MSDN文档,递归思想
         this.Invoke(call, new object[] { text });
     }
     else
     {
         this.labelResult.Text = text;
     }
 }
Example #35
0
 private void ShowLog(string text)
 {
     if (this.logRichTxt.InvokeRequired)
     {
         SetTextCallBack stcb = new SetTextCallBack(ShowLog);
         this.Invoke(stcb, new object[] { text });
     }
     else
     {
         this.logRichTxt.Text = string.Format("{0}\r\n{1}", this.logRichTxt.Text, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "  " + text);
     }
 }
Example #36
0
 private void SetText2(string text)
 {
     if (this.lbBarcode.InvokeRequired)
     {
         SetTextCallBack d = new SetTextCallBack(SetText2);
         this.Invoke(d, new object[] { text });
     }
     else
     {
         lbBarcode.Text = text;
     }
 }
Example #37
0
 private void SetText(string text)
 {
     if (this.lbGTInput.InvokeRequired)
     {
         SetTextCallBack d = new SetTextCallBack(SetText);
         this.Invoke(d, new object[] { text });
     }
     else
     {
         lbGTInput.Text = text;
     }
 }
Example #38
0
 private void SetTextHTML(string tekst)
 {
     if (webBrowser1.InvokeRequired)
     {
         SetTextCallBack f = new SetTextCallBack(SetTextHTML);
         this.Invoke(f, new object[] { tekst });
     }
     else
     {
         this.webBrowser1.Document.Write(tekst);
     }
 }
Example #39
0
 private void SetReceivedText(string text)
 {
     if (this.ServerConsoleListBox.InvokeRequired)
     {
         SetTextCallBack d = new SetTextCallBack(SetReceivedText);
         this.Invoke(d, new object[] { text });
     }
     else
     {
         this.ServerConsoleListBox.Items.Add(text);
     }
 }
 public void displayStatusText(string msg)
 {
     if (lblStatus.InvokeRequired)
     {
         SetTextCallBack d = new SetTextCallBack(displayStatusText);
         this.Invoke(d, new object[] { msg });
     }
     else
     {
         this.lblStatus.Text = msg;
     }
 }
Example #41
0
        //write to displaybox in thread
        public void SetText(string text)
        {
            if (dataDisplayBox.InvokeRequired)
            {
                SetTextCallBack st = new SetTextCallBack(SetText);
                this.Invoke(st, new object[] { text });

            }
            else
            {
                dataDisplayBox.AppendText(text + "\n");
                if (this.checkBox_AutoscrollDown.Checked)
                {
                    this.dataDisplayBox.ScrollToCaret();
                }

            }
        }
Example #42
0
        /// <summary>
        /// Function Name: checker
        /// Created By: Kyle Avery
        /// Created On: 4/4/2013
        /// Updated On: n/a
        /// Relys On: a string to be passed in
        /// Purpose: checks the threads and passes a string safely between them
        /// </summary>
        /// <param name="text"> text is the string we are going to pass between threads</param>
        private void setErrorText(string text)
        {
            if(this.l_errorCode.InvokeRequired)
            {
                try
                {
                    SetTextCallBack d = new SetTextCallBack(setErrorText);
                    this.Invoke(d, new object[] { text });
                }
                catch
                {

                }
            }
            else
            {
                this.l_errorCode.Text = text;
            }
        }
Example #43
0
        /// <summary>
        /// This method is responsible for displaying recieved data in textBox.
        /// (ThreadSafety!)
        /// </summary>
        /// <param name="msg"></param>
        public void addDataToDisplay(String msg)
        {
            if (this.textBox1.InvokeRequired)
            {
                SetTextCallBack d = new SetTextCallBack(addDataToDisplay);
                try
                {
                    this.Invoke(d, new object[] { msg });
                }
                catch (Exception e)
                {
                    Form1.logException("Exception while adding to Console.textBox1 msg = " + e.Message);
                }
            }
            else
            {
                try
                {
                    char[] arr = msg.ToCharArray();
                    int indexer = 0;
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < arr.Length; i++)
                    {
                        if (arr[i] != '!')
                        {
                            sb.Append(arr[i]);
                        }
                        else
                        {
                            switch (indexer)
                            {
                                case 0:
                                    {
                                        textBox1.Text = sb.ToString();
                                        break;
                                    }

                                case 1:
                                    {
                                        textBox2.Text = sb.ToString();
                                        break;
                                    }

                                case 2:
                                    {
                                        textBox3.Text = sb.ToString();
                                        break;
                                    }

                                case 3:
                                    {
                                        textBox4.Text = sb.ToString();
                                        break;
                                    }

                                case 4:
                                    {
                                        textBox5.Text = sb.ToString();
                                        break;
                                    }

                                case 5:
                                    {
                                        if(sb.ToString().Equals("0"))
                                        {
                                            radioButton1.Enabled = true;
                                            radioButton1.Select();
                                            radioButton2.Enabled = false;
                                        }
                                        else
                                        {
                                            radioButton1.Enabled = false;
                                            radioButton2.Enabled = true;
                                            radioButton2.Select();
                                        }
                                        break;
                                    }
                            }

                            sb = null;
                            sb = new StringBuilder();
                            indexer++;
                        }
                    }

                }
                catch (Exception e)
                {
                    Form1.logException("Exception while adding to Console.textBox1 msg = " + e.Message);
                }
            }
        }
Example #44
0
 public void displayStatusText(string msg)
 {
     if (outputBox.InvokeRequired)
     {
         SetTextCallBack d = new SetTextCallBack(displayStatusText);
         this.Invoke(d, new object[] { msg });
     }
     else
     {
         this.outputBox.Text += msg + "\n";
         outputBox.SelectionStart = outputBox.Text.Length;
         outputBox.ScrollToCaret ();
     }
 }
Example #45
0
 public void displayOutgoingText(string msg)
 {
     if (codeBox.InvokeRequired)
     {
         SetTextCallBack d = new SetTextCallBack(displayOutgoingText);
         this.Invoke(d, new object[] { msg });
     }
     else
     {
         this.codeBox.Text = msg;
         codeBox.SelectionStart = codeBox.Text.Length;
         codeBox.ScrollToCaret ();
     }
 }