private void btnTest_Click(object sender, System.EventArgs e)
        {
            // Loop a few times.
            for (int Counter = 1; Counter <= Int32.Parse(txtCycles.Text); Counter++)
            {
                // Display some text on screen.
                txtCurrent.Text = Counter.ToString();
                txtCurrent.Update();

                // Cause the application to sleep.
                System.Threading.Thread.Sleep(Int32.Parse(txtSleep.Text));
            }

            // Tell the user we're finished.
            txtCurrent.Text = "Done";
        }
Example #2
0
 public void SetText(string sText)
 {
     // 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.textBox1.InvokeRequired)
     {
         var d = new SetTextCallback(SetText);
         Invoke(d, new object[] { sText });
     }
     else
     {
         textBox1.Text = sText;
         textBox1.Update();
         textBox1.Refresh();
     }
 }
Example #3
0
        private void WriteHexData(Color rgb)
        {
            string red = Convert.ToString(rgb.R, 16);

            if (red.Length < 2)
            {
                red = "0" + red;
            }
            string green = Convert.ToString(rgb.G, 16);

            if (green.Length < 2)
            {
                green = "0" + green;
            }
            string blue = Convert.ToString(rgb.B, 16);

            if (blue.Length < 2)
            {
                blue = "0" + blue;
            }

            m_txt_Hex.Text = red.ToUpper() + green.ToUpper() + blue.ToUpper();
            m_txt_Hex.Update();
        }
Example #4
0
 private void UpdateStatus(TextBox lbl, string status)
 {
     if (lbl.InvokeRequired)
     {
         lbl.BeginInvoke(new Action<TextBox, string>(UpdateStatus), lbl, status);
     }
     else
     {
         lbl.Text = status;
         lbl.Update();
         lbl.Parent.Update();
     }
 }
 private static void LogAddLine(TextBox tb, StringBuilder sb, string line)
 {
     sb.Append(line);
     //tb.BeginInvoke((MethodInvoker)(() => tb.Text = sb.ToString()));
     tb.Text = sb.ToString();
     tb.Update();
 }
 /// <summary>
 /// Will update Text in a Text Box when the UI thread is still busy
 /// </summary>
 /// <param name="myTextBox">The TextBox control to update</param>
 /// <param name="myText">The Text to update</param>
 private void HELPER_updateTextBox(TextBox myTextBox, string myText)
 {
     myTextBox.Text = myText;
     myTextBox.Invalidate();
     myTextBox.Update();
     myTextBox.Refresh();
     Application.DoEvents();
 }
Example #7
0
        string SetTextBoxText(TextBox textbox,
            string strText)
        {
            string strOldText = textbox.Text;

            textbox.Text = strText;
            textbox.Update();

            return strOldText;
        }
Example #8
0
        // 线程安全版本
        string Safe_SetTextBoxText(TextBox textbox,
            string strText)
        {
            if (textbox.Parent != null && textbox.Parent.InvokeRequired)
            {
                Delegate_SetTextBoxText d = new Delegate_SetTextBoxText(SetTextBoxText);
                return (string)textbox.Parent.Invoke(d, new object[] { textbox, strText });
            }
            else
            {
                string strOldText = textbox.Text;

                textbox.Text = strText;
                textbox.Update();


                return strOldText;
            }
        }
 protected void FlushMessages(List<string> messages, TextBox textBox)
 {
     for (int n = 0; n < messages.Count; ++n)
     textBox.Text += messages[n] + System.Console.Out.NewLine;
       messages.Clear();
       textBox.Update();
 }