views:

69

answers:

2

I'm looking for a winforms control that can output text like in a console window (output is appended to the bottom, color formatting, etc.) Much like the "output" window in most IDEs.

I tried making one myself but it didn't work the way I wanted, so I'm wondering if there is some existing control out there.

This is for an open-source project.

A: 

I have wrote a simple control. But it does not work with colors (its derived 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; }
        }
    }

Usage:

//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
Markos
A: 

What about RichTextBox Control (built-in) ? Or maybe you could use ListView since it can be useful for irc. Especially ObjectListView gives a lot of possibilities.

MadBoy