-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConsoleControl.cs
63 lines (52 loc) · 1.66 KB
/
ConsoleControl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Text;
namespace rec.robotino.api2.examples.camera
{
/// <summary>
/// Console control.
/// All standard text output (e.g. through calling System.out.print()) is diverted to this text area.
/// </summary>
public partial class ConsoleControl : UserControl
{
public ConsoleControl()
{
InitializeComponent();
TextBoxWriter writer = new TextBoxWriter(textBoxConsole);
Console.SetOut(writer);
Console.SetError(writer);
}
private class TextBoxWriter : TextWriter
{
private delegate void WriteTextDelegate(string text);
private readonly TextBox textbox;
private readonly WriteTextDelegate writeTextDelegate;
public TextBoxWriter(TextBox textbox)
{
this.textbox = textbox;
this.writeTextDelegate = new WriteTextDelegate(WriteToTextBox);
}
public override void Write(char value)
{
Write(value.ToString());
}
public override void Write(string value)
{
if (textbox.InvokeRequired)
textbox.Invoke(writeTextDelegate, value);
}
private void WriteToTextBox(string value)
{
textbox.AppendText(value);
}
public override System.Text.Encoding Encoding
{
get { return new UTF8Encoding(); }
}
}
}
}