The main implementation method is to inherit the tracelinster class, override the construction parameters, and override the write and writeline methods. The specific code is as follows:
Code
1 public class controltracelistener: tracelistener
2 {
3 private control _ control;
4 private stringsenddelegate _ invokewrite;
5 private delegate void stringsenddelegate (string MSG );
6
7 public controltracelistener (control target)
8 {
9 _ control = target;
10 _ invokewrite = new stringsenddelegate (sendstring );
11}
12
13 public override void write (string message)
14 {
15 _ control. Invoke (_ invokewrite, new object [] {message });
16}
17
18 public override void writeline (string message)
19 {
20 _ control. Invoke (_ invokewrite, new object [] {message + environment. newline });
21}
22
23 private void sendstring (string MSG)
24 {
25 // No need to lock control as this function will only
26 // ever be executed from the UI thread
27 _ control. Text + = MSG;
28}
29}
30