Here's an axample
Just curious, I'm new with C#, but I decided to use it to develop my server for my Java game simply because I wanted a nice server-gui, but I'm starting to realize this would be just as easy to do with Swing...
Here's an axample
Just curious, I'm new with C#, but I decided to use it to develop my server for my Java game simply because I wanted a nice server-gui, but I'm starting to realize this would be just as easy to do with Swing...
I did a similar project over the weekend, I used this link to forward all Console data to a textbox. You could use any similar control with minor tweaks.
public class TextBoxStreamWriter : TextWriter
{
TextBox _output = null;
public TextBoxStreamWriter(TextBox output)
{
_output = output;
}
public override void Write(char value)
{
base.Write(value);
_output.AppendText(value.ToString()); // When character data is written, append it to the text box.
}
public override Encoding Encoding
{
get { return System.Text.Encoding.UTF8; }
}
}
All of the Write(...) and WriteLine(...) trickle down to Write(char) so it's the only method that you need to override.
My example required the form to also have a public TextBox property which exposed the private TextBox inside the form.
TextWriter consoleRedirect = new Tools.TextBoxStreamWriter(consoleForm.TxtOuputDisplay);
Console.SetOut(consoleRedirect);
Well I already wrote this up before I saw the previous comment. But since I took the time I will post it anyway.
public void WriteLog(TextBox tb ,string log)
{
tb.AppendText(log + "\n");
}
private void button1_Click(object sender, EventArgs e)
{
WriteLog(textBox1, "[App]: This is a log string");
WriteLog(textBox1, "[App]: Another log string");
WriteLog(textBox1, "[App]: Yet another etc etc.");
}
Where textBox1 is a Multi-line textbox with a black backcolor and blue foreground text. The above comment is a more elegant solution but this will get you by if you want something quick and easy. I dont have enough rep to post an image inline but here is what it looks like. http://imageshack.us/photo/my-images/198/logwindow.jpg/