Debug接口

Debug接口IDebugOut 定义 Code1usingSy 2usingSystem Collections Generic 3usingSystem Text 4usingSystem Windows Forms 56

大家好,欢迎来到IT知识分享网。

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

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/131350.html

(0)
上一篇 2025-08-08 16:45
下一篇 2025-08-08 17:00

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信