Exemple #1
0
 public static void AppendText(TextBoxBase control, string text)
 {
     if (control.InvokeRequired)
         control.Invoke(new AppendTextDelegate(AppendText), control, text);
     else
         control.AppendText(text);
 }
Exemple #2
0
 public TextBoxTracer(TextBoxBase t, StringCollection data)
 {
     this.txtLog = t;
     this.logData = data;
     writeAction = s => t.Invoke(new Action(() =>
     {
         t.Text += s;
     }));
 }
Exemple #3
0
 public static void AppendTextCrossThread(this TextBoxBase textBox, string format, params object[] args)
 {
     if (textBox.InvokeRequired)
     {
         Action <TextBoxBase, string> action = new Action <TextBoxBase, string>(AppendTextCrossThread);
         textBox.Invoke(action, new object[] { textBox, string.Format(format, args) });
     }
     else
     {
         textBox.AppendText(string.Format(format, args));
     }
 }
Exemple #4
0
 public static void AppendTextCrossThread(this TextBoxBase textBox, string text)
 {
     if (textBox.InvokeRequired)
     {
         Action <TextBoxBase, string> action = new Action <TextBoxBase, string>(AppendTextCrossThread);
         textBox.Invoke(action, new object[] { textBox, text });
     }
     else
     {
         textBox.AppendText(text);
     }
 }
Exemple #5
0
 public static void ClearCrossThread(this TextBoxBase textBox)
 {
     if (textBox.InvokeRequired)
     {
         Action <TextBoxBase> action = new Action <TextBoxBase>(ClearCrossThread);
         textBox.Invoke(action, new object[] { textBox });
     }
     else
     {
         textBox.Clear();
     }
 }
 public static void AppendText(TextBoxBase tb, string text)
 {
     if (tb == null) return;
     tb.SuspendLayout();
     if (tb.InvokeRequired)
     {
         tb.Invoke(new AppendTextDelegate(AppendText), new object[] { tb, text });
     }
     else
     {
         tb.SelectionStart = tb.TextLength;
         tb.SelectedText = text;
     }
     tb.ResumeLayout();
 }
Exemple #7
0
 /// <summary>
 /// Sets the caret position in a text box.
 /// This is just a helper function that takes care of
 /// cross-thread invokations that would result in .NET
 /// exceptions.
 /// </summary>
 public static void SetCaretPosition(TextBoxBase textBox, int position)
 {
     if (textBox.InvokeRequired)
     {
         textBox.Invoke(new setCaretPosition(SetCaretPosition), textBox, position);
     }
     else
     {
         textBox.SelectionStart = position;
     }
 }
Exemple #8
0
        /// <summary>
        /// Returns selected text in the text box
        /// </summary>
        /// <param name="control">text box</param>
        /// <returns>selected text</returns>
        public static String GetSelectedText(TextBoxBase control)
        {
            if (control.InvokeRequired)
            {
                return (String)control.Invoke(new getSelectedText(GetSelectedText), control);
            }

            return control.SelectedText;
        }
Exemple #9
0
 /// <summary>
 /// Returns the caret position in a text box.
 /// This is just a helper function that takes care of
 /// cross-thread invokations that would result in .NET
 /// exceptions.
 /// </summary>
 public static int GetCaretPosition(TextBoxBase textBox)
 {
     if (textBox.InvokeRequired)
     {
         return (int)textBox.Invoke(new getCaretPosition(GetCaretPosition), textBox);
     }
     else
     {
         return textBox.SelectionStart;
     }
 }
Exemple #10
0
 /// <summary>
 /// Unselect text in textbox
 /// </summary>
 /// <param name="control">the text box control</param>
 public static void UnselectText(TextBoxBase control)
 {
     if (control.InvokeRequired)
     {
         control.Invoke(new unselectText(UnselectText), control);
     }
     else
     {
         control.SelectionLength = 0;
         if (!String.IsNullOrEmpty(control.Text))
         {
             control.Select(control.Text.Length, 0);
         }
     }
 }
 /// <summary>
 /// Recupera de forma segura o conteúdo do TextBox.
 /// </summary>
 /// <returns>Conteúdo do TextBox.</returns>
 private string RecuperarTexto(TextBoxBase txt)
 {
     if (txt.InvokeRequired)
     {
         RecuperarTextoCallback método = new RecuperarTextoCallback(RecuperarTexto);
         try
         {
             return (string)txt.Invoke(método, txt);
         }
         catch (Exception)
         {
             return "";
         }
     }
     else
         return txt.Text;
 }