public static void SetTextBoxText(TextBox textBox, string text)
 {
     if (textBox.InvokeRequired)
     {
         textBox.BeginInvoke(new Action(() =>
         {
             textBox.Text = text;
         }));
     }
     else
     {
         textBox.Text = text;
     }
 }
Example #2
0
 public override void Write(string value)
 {
     if (_textBox.IsHandleCreated)
     {
         _textBox.BeginInvoke(new ThreadStart(() => _textBox.AppendText(value + " ")));
     }
 }
Example #3
0
 public override void Write(string value)
 {
     if (_textBox.IsHandleCreated)
     {
         _textBox.BeginInvoke(new ThreadStart(() =>
         {
             _textBox.AppendText("[" + count.ToString() + "]" + value + " ");
             count++;
         }));
     }
 }
Example #4
0
 /// <summary>
 /// 输出信息
 /// </summary>
 /// <param name="txtbox"></param>
 /// <param name="message"></param>
 /// <param name="type"></param>
 private void WriteToTextBox(System.Windows.Forms.TextBox txtbox, string message, string type, DateTime time)
 {
     try
     {
         if (txtbox.InvokeRequired)
         {
             Action actionDelegate = () =>
             {
                 string info = time + "\t" + type + "\t" + message;
                 txtbox.AppendText(info);
                 txtbox.AppendText(Environment.NewLine);
                 txtbox.AppendText(Environment.NewLine);
                 txtbox.ScrollToCaret();
             };
             txtbox.BeginInvoke(actionDelegate);
         }
         else
         {
             string info = time + "\t" + type + "\t" + message;
             txtbox.AppendText(info);
             txtbox.AppendText(Environment.NewLine);
             txtbox.AppendText(Environment.NewLine);
             txtbox.ScrollToCaret();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("写入内容时发生错误:" + txtbox.Name + ":" + message);
     }
 }
Example #5
0
 public void SetTextBoxText(TextBox anything, string text)
 {
     anything.BeginInvoke((MethodInvoker)delegate
     {
         anything.Text = text;
     });
 }
Example #6
0
        private void UpdateTextBox(string message, bool newSection = false, bool error = false)
        {
            if (textBox == null)
            {
                return;
            }
            textBox.BeginInvoke((MethodInvoker) delegate {
                if (newSection)
                {
                    textBox.AppendText("-------------------------------" +
                                       Environment.NewLine);
                }

                if (error)
                {
                    textBox.AppendText("===== ВНИМАНИЕ! ОШИБКА! =====" +
                                       Environment.NewLine);
                }

                textBox.AppendText(DateTime.Now.ToString("HH:mm:ss") + ": " +
                                   message + Environment.NewLine);
            });

            LoggingSystem.LogMessageToFile(message);
        }
 public void UpdateTextBoxInvoke(TextBox box, string displayText, int linesToshow)
 {
     Object[] args = new object[3];
     args[0] = box;
     args[1] = displayText;
     args[2] = linesToshow;
     box.BeginInvoke(textBoxDelegate, args);
 }
Example #8
0
 public override void Log(object obj, string message)
 {
     lock (lockObj)
     {
         System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)obj;
         tb.BeginInvoke((MethodInvoker) delegate()
         {
             tb.AppendText(message + Environment.NewLine);
         });
     }
 }
Example #9
0
        /// <summary>
        /// 显示信息
        /// </summary>
        /// <param name="txtInfo"></param>
        /// <param name="Info"></param>
        public static void ShowInfo(System.Windows.Forms.TextBox txtInfo, string Info)
        {
            string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string info = string.Empty;

            info = time + " :" + Info;

            txtInfo.BeginInvoke((MethodInvoker) delegate() {
                txtInfo.AppendText(info);
                txtInfo.AppendText(Environment.NewLine);
                txtInfo.ScrollToCaret();
            });
        }
Example #10
0
 public static void AppendToTextBox(string text, TextBox txtBox)
 {
     if (txtBox.InvokeRequired)
     {
         txtBox.BeginInvoke(
             new MethodInvoker(delegate() { AppendToTextBox(text, txtBox); })
         );
     }
     else
     {
         txtBox.AppendText(text);
     }
 }
        //protected override void Append(log4net.Core.LoggingEvent LoggingEvent)
        //{
        //    System.IO.StringWriter stringWriter = new System.IO.StringWriter(System.Globalization.CultureInfo.InvariantCulture);
        //    Layout.Format(stringWriter, LoggingEvent);
        //    _textBox.AppendText(stringWriter.ToString());
        //}

        protected override void Append(LoggingEvent LoggingEvent)
        {
            if (_textBox != null)
            {
                if (_textBox.InvokeRequired)
                {
                    _textBox.BeginInvoke(new UpdateControlDelegate(UpdateControl), new object[] { LoggingEvent });
                }
                else
                {
                    UpdateControl(LoggingEvent);
                }
            }
        }
Example #12
0
 public static void AppendTextToTxtLog(string str, TextBox t)
 {
     if (t.InvokeRequired)
     {
         t.BeginInvoke(new Action<string>(s =>
             {
                 t.Text = string.Format("{0}\r\n{1}", s, t.Text);
             }), str);
     }
     else
     {
         t.Text = string.Format("{0}\r\n{1}", str, t.Text);
     }
 }
Example #13
0
        private void UpdateTextBox(string message, bool isError = false, bool isNewSection = false)
        {
            if (textBox == null)
            {
                return;
            }

            textBox.BeginInvoke((MethodInvoker) delegate {
                if (isError)
                {
                    message = "---ОШИБКА--- " + message;
                }

                if (isNewSection)
                {
                    textBox.AppendText("-------------------------------" + Environment.NewLine);
                }

                textBox.AppendText(DateTime.Now.ToString("HH:mm:ss") + ": " + message + Environment.NewLine);
            });
        }
Example #14
0
 public void WriteLine(String text)
 {
     outputTextBox.BeginInvoke(new AppendTextDelegate(outputTextBox.AppendText),
                               new object[] { text + Environment.NewLine });
 }
Example #15
0
 public void SetTextBoxState(TextBox anything, bool state)
 {
     anything.BeginInvoke((MethodInvoker)delegate
     {
         try
         {
             anything.Enabled = state;
         }
         catch
         {
         }
     });
 }
Example #16
0
 // disposer chaque text recue a sa position finale
 private static void SetText(TextBox box, string text)
 {
     if (box.InvokeRequired) // 
         box.BeginInvoke(new Action(() => SetText(box, text)));
     else
         box.Text = text;
 }
Example #17
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();
     }
 }
Example #18
0
 private void SetTextSafe(TextBox txtBox, string newText)
 {
     if (txtBox.InvokeRequired)
     {
         txtBox.BeginInvoke(_delegateSetTextSafe, txtBox, newText);
     }
     else
     {
         var sb = new StringBuilder(newText);
         sb.Append(txtBox.Text);
         txtBox.Text = sb.ToString();
     }
 }
Example #19
0
 public static void ShowMsgInTextBox(TextBox box, string msg, bool logInConsole = true)
 {
     if (box == null)
     {
         return; // TextBox对象不存在
     }
     else
     {
         MethodInvoker action = () => box.AppendText(msg + "\r\n");
         try
         {
             box.BeginInvoke(action);
         }
         catch (InvalidOperationException ex)
         {
             BstLogger.Instance.Log(ex.ToString()); // 有的时候在显示的时候TextBox已经被销毁,忽略错误
         }
     }
     if (logInConsole)
     {
         BstLogger.Instance.Log(msg);
     }
 }
 /// <summary>
 /// Method to update text on a textbox.
 /// </summary>
 /// <param name="msg">String type message</param>
 /// <param name="box">Textbox to set text</param>
 private void SetTextboxMsg(string msg, TextBox box)
 {
     if (box.InvokeRequired)
     {
         object[] pList = { msg, box };
         box.BeginInvoke(new SetTextboxMsgCallBack(SetTextboxMsg), pList);
     }
     else
     {
         box.Text = msg;
     }
 }
Example #21
0
 void SetText(TextBox eb, string s)
 {
     if (eb.InvokeRequired)
         eb.BeginInvoke(new SetTextDel(DoSetText), new object[] {eb, s});
     else
         DoSetText(eb, s);
 }