Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Writes output to a windows form using InvokeRequired property
- /// </summary>
- /// <param name="formatOrValue">Value to write or format used in formating strings</param>
- /// <param name="args">Parameters used in formatting strings</param>
- void WriteOutput(object formatOrValue,params object[] args) {
- string text = string.Empty;
- if(args == null || args.Length == 0) {
- if(formatOrValue != null)
- text = formatOrValue.ToString();
- else
- text = string.Empty;
- }
- else {
- text = string.Format(formatOrValue.ToString(),args);
- }
- text += Environment.NewLine;
- Action<string> writeAction = (s) => {
- richTextBox1.AppendText(s);
- ScrollOutputToCaret();
- };
- if(InvokeRequired)
- BeginInvoke(new Action<string>(writeAction),text);
- else
- writeAction(text);
- }
- void ScrollOutputToCaret() {
- if(richTextBox1.TextLength == 0)
- return;
- richTextBox1.Select(richTextBox1.TextLength,1);
- richTextBox1.ScrollToCaret();
- }
- void ClearOutput() {
- Action actionInvoke = () => {
- richTextBox1.Clear();
- };
- if(InvokeRequired)
- Invoke(actionInvoke);
- else
- actionInvoke();
- }
Advertisement
Add Comment
Please, Sign In to add comment