Debug接口

IDebugOut定义:

ContractedBlock.gif ExpandedBlockStart.gif Code
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Text;
 4 using System.Windows.Forms;
 5 
 6 namespace Com.Debug
 7 {
 8     /// <summary>
 9     /// Debug Out Interface
10     /// </summary>
11     public interface IDebugOut
12     {
13         //event SourceDebugOutEventHandler SourceDebugOut;
14 
15         /// <summary>
16         /// 可视UI
17         /// </summary>
18         Control ShowUI
19         {
20             get;
21             set;
22         }
23         /// <summary>
24         /// 显示UI
25         /// </summary>
26         void Show();
27         /// <summary>
28         /// UI是否关闭
29         /// </summary>
30         bool IsClose
31         {
32             get;
33         }
34         /// <summary>
35         /// 触发Debug事件
36         /// </summary>
37         /// <param name="args">相关信息</param>
38         void FireDebug(object sender,SourceDebugOutArgs args);
39       
40         /// <summary>
41         /// 继续监视
42         /// </summary>
43         void    Resume();
44         /// <summary>
45         /// 挂起监视
46         /// </summary>
47         void Suspend();
48     }
49 }
50 
51 

 

BaseDebugOut定义:

ContractedBlock.gif ExpandedBlockStart.gif Code
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Text;
  4 using System.Windows.Forms;
  5 
  6 namespace Com.Debug
  7 {
  8     public abstract class BaseDebugOut : IDebugOut
  9     {
 10 
 11         #region IDebugOut 成员
 12 
 13         //public event SourceDebugOutEventHandler SourceDebugOut;
 14 
 15         public virtual void FireDebug(object sender, SourceDebugOutArgs args)
 16         {
 17         }
 18 
 19         public void FireDebug(object sender)
 20         {
 21             if (_bState)
 22                 FireDebug(sender,new SourceDebugOutArgs());
 23         }
 24 
 25         public void FireDebug(object sender, string message)
 26         {
 27             if (_bState)
 28                 FireDebug(sender, new SourceDebugOutArgs(message));
 29         }
 30 
 31         public void FireDebug(object sender, string message, object tag)
 32         {
 33             if (_bState)
 34                 FireDebug(sender,new SourceDebugOutArgs(message,tag));
 35         }
 36 
 37         private Control _controlUI;
 38         public virtual Control ShowUI
 39         {
 40             get { return _controlUI; }
 41             set { _controlUI = value; }
 42         }
 43 
 44         public virtual  void Show()
 45         {
 46             if (ShowUI is Form)
 47             {
 48                Form form=  ShowUI as Form;
 49                if (form != null)
 50                {
 51                    form.Show();
 52                    form.FormClosing += new FormClosingEventHandler(form_FormClosing);
 53                    _bClose = false;
 54                }
 55             }
 56             else if(ShowUI is Control)
 57             {
 58                 DebugOutForm form = new DebugOutForm();
 59                 ShowUI.Parent = form.ControlPanel;
 60                 ShowUI.Dock = DockStyle.Fill;
 61                 form.Show();
 62                 form.FormClosing += form_FormClosing;
 63                 _bClose = false;
 64             }
 65         }
 66 
 67         void form_FormClosing(object sender, FormClosingEventArgs e)
 68         {
 69             _bClose = true;
 70         }
 71 
 72         private bool _bClose = false;
 73         /// <summary>
 74         /// ShowUI 是否关闭
 75         /// </summary>
 76         public bool IsClose
 77         {
 78             get { return _bClose; }
 79         }
 80 
 81         private bool _bState = true;
 82         /// <summary>
 83         /// 继续
 84         /// </summary>
 85         public void Resume()
 86         {
 87             _bState = true;
 88         }
 89 
 90         /// <summary>
 91         /// 挂起
 92         /// </summary>
 93         public void Suspend()
 94         {
 95             _bState = false;
 96         }
 97         #endregion
 98     }
 99 }
100 
101 

 

SourceDebugOutArgs定义:

ContractedBlock.gif ExpandedBlockStart.gif Code
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Text;
 4 
 5 namespace Com.Debug
 6 {
 7     /// <summary>
 8     /// 事件相关信息
 9     /// </summary>
10     public sealed class SourceDebugOutArgs:EventArgs
11     {
12         public SourceDebugOutArgs()
13         {
14             this._fireTime = DateTime.Now.ToLongTimeString();
15         }
16 
17         public SourceDebugOutArgs(string message):this()
18         {
19             this.Message = message;
20         }
21 
22         public SourceDebugOutArgs(string message, object tag)
23             : this(message)
24         {
25             this.Tag = tag;
26         }
27 
28         private string _message;
29         /// <summary>
30         /// Debug 信息
31         /// </summary>
32         public string Message
33         {
34             get { return _message; }
35             set { _message = value; }
36         }
37 
38         private string _fireTime;
39         /// <summary>
40         /// 发生时间
41         /// </summary>
42         public string FireTime
43         {
44             get { return _fireTime; }
45         }
46 
47         private object _tag;
48         /// <summary>
49         /// 附加信息
50         /// </summary>
51         public object Tag
52         {
53             get { return _tag; }
54             set { _tag = value; }
55         }
56 
57     }
58 }
59 
60 

 

具体实现:

FormDebugOut定义:

ContractedBlock.gif ExpandedBlockStart.gif Code
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Text;
 4 using Com.Debug;
 5 
 6 namespace FormDebugText
 7 {
 8     /// <summary>
 9     /// 输出类
10     /// </summary>
11     public class FormDebugOut:BaseDebugOut
12     {
13         public override string ToString()
14         {
15             return "FormDebugOut";
16         }
17         private DebugOutText _outText;
18 
19         public FormDebugOut()
20         {
21             
22         }
23         #region 重写函数
24 
25         public override void FireDebug(object sender, SourceDebugOutArgs args)
26         {
27             base.FireDebug(sender, args);
28             _outText.BeginInvoke(new SourceDebugOutEventHandler(DebugOut), new object[] { sender, args });
29         }
30         #endregion
31 
32         private void DebugOut(object sender,SourceDebugOutArgs args)
33         {
34             if (args != null)
35                 _outText.WriteLine(args.Message);
36             else
37                 _outText.WriteLine(sender.ToString());
38         }
39 
40         public override void Show()
41         {
42             _outText = new DebugOutText();
43             this.ShowUI = _outText;
44             base.Show();
45         }
46     }
47 }
48 
49 

 

DebugOutText定义:

ContractedBlock.gif ExpandedBlockStart.gif Code
 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Drawing;
 5 using System.Data;
 6 using System.Text;
 7 using System.Windows.Forms;
 8 
 9 namespace FormDebugText
10 {
11     public partial class DebugOutText : UserControl
12     {
13         public DebugOutText()
14         {
15             InitializeComponent();
16         }
17 
18         public void WriteLine(string mesage)
19         {
20             if (richTextBox1.Lines.Length > 2000)
21             {
22                 richTextBox1.Text = "";
23             }
24 
25             StringBuilder build = new StringBuilder(this.richTextBox1.Text);
26             this.richTextBox1.Text = build.Insert(0, mesage + "\r\n").ToString();
27         }
28     }
29 }
30 
31 

 

转载于:https://www.cnblogs.com/ZlgHimm/archive/2008/11/27/Debug.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值