Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1452 | chris | 1 | #region License |
| 2 | // |
||
| 3 | // The Open Toolkit Library License |
||
| 4 | // |
||
| 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. |
||
| 6 | // |
||
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
||
| 8 | // of this software and associated documentation files (the "Software"), to deal |
||
| 9 | // in the Software without restriction, including without limitation the rights to |
||
| 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
||
| 11 | // the Software, and to permit persons to whom the Software is furnished to do |
||
| 12 | // so, subject to the following conditions: |
||
| 13 | // |
||
| 14 | // The above copyright notice and this permission notice shall be included in all |
||
| 15 | // copies or substantial portions of the Software. |
||
| 16 | // |
||
| 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||
| 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
||
| 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
||
| 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
||
| 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
||
| 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||
| 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
||
| 24 | // OTHER DEALINGS IN THE SOFTWARE. |
||
| 25 | // |
||
| 26 | #endregion |
||
| 27 | |||
| 28 | using System; |
||
| 29 | using System.Collections.Generic; |
||
| 30 | using System.Text; |
||
| 31 | using System.Diagnostics; |
||
| 32 | using System.Windows.Forms; |
||
| 33 | using System.Threading; |
||
| 34 | |||
| 35 | namespace Examples |
||
| 36 | { |
||
| 37 | public class TextBoxTraceListener : TraceListener |
||
| 38 | { |
||
| 39 | TextBox _target; |
||
| 40 | StringSendDelegate _invokeWrite; |
||
| 41 | |||
| 42 | public TextBoxTraceListener(TextBox target) |
||
| 43 | { |
||
| 44 | _target = target; |
||
| 45 | _invokeWrite = new StringSendDelegate(SendString); |
||
| 46 | } |
||
| 47 | |||
| 48 | public override void Write(string message) |
||
| 49 | { |
||
| 50 | if (_target.Created) |
||
| 51 | _target.BeginInvoke(_invokeWrite, new object[] { message }); |
||
| 52 | } |
||
| 53 | |||
| 54 | public override void WriteLine(string message) |
||
| 55 | { |
||
| 56 | if (_target.Created) |
||
| 57 | _target.BeginInvoke(_invokeWrite, new object[] { message + Environment.NewLine }); |
||
| 58 | } |
||
| 59 | |||
| 60 | private delegate void StringSendDelegate(string message); |
||
| 61 | private void SendString(string message) |
||
| 62 | { |
||
| 63 | if (_target.Created) |
||
| 64 | { |
||
| 65 | // No need to lock text box as this function will only |
||
| 66 | // ever be executed from the UI thread |
||
| 67 | _target.Text += message; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | } |
||
| 71 | } |