Console Text Management?

I am looking for a winforms control that can output text, for example, in a console window (output is added at the bottom, color formatting, etc.). Similar to the "exit" window in most IDEs.

I tried to do it myself, but it didn’t work the way I wanted, so I wonder if there is any existing control there.

This is for an open source project.

+3
source share
2 answers

I wrote a simple control. But it does not work with colors (its output from textWriter, which does not support colors).

internal class TextBoxWriter : TextWriter {
    TextBox _output;

    public TextBoxWriter(TextBox output) {
        _output = output;
    }

    public override void WriteLine(string value) {
        Write(value + System.Console.Out.NewLine);
    }

    public override void Write(string value) {
        if(_output.InvokeRequired) {
            _output.BeginInvoke((Action<string>)Write, value);
        } else {
            _output.AppendText(value);
        }
    }

    public override void Write(char value) {
        Write(value.ToString());
    }

        public override Encoding Encoding {
            get { return Encoding.UTF8; }
        }
    }

Using:

//designer code
private System.Windows.Forms.TextBox outputTextBox;
this.outputTextBox = new System.Windows.Forms.TextBox();

//user code
var _textWriter = new TextBoxWriter();
System.Console.SetOut(_textWriter);
Console.WriteLine("hello");   //this will be show in the outputTextBox
+1
source

RichTextBox ()? , , ListView, irc. ObjectListView .

0

Source: https://habr.com/ru/post/1756465/


All Articles