我只做了正确与错误的显示,其它的可以跟据枚举操作
环境: .NET 2.0
1
using
System;
2 using System.Collections;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Windows.Forms;
6 using System.IO;
7
8
9 namespace ProCtrlLib
10 {
11 /**//// <summary>
12 /// 描述:采用LISTVIEW形式加载消息
13 /// 作者:ForrestSun
14 /// 日期: 2006-7-17
15 /// </summary>
16
17 [ToolboxBitmap(typeof(ProMessageBox), "ProMessageBox")]
18 public partial class ProMessageBox : UserControl
19 {
20
21 public ProMessageBox()
22 {
23 InitializeComponent();
24 }
25
26
27 private void cmnuClearInfo_Click(object sender, EventArgs e)
28 {
29 ClearInfo();
30 }
31
32 function#region function
33 delegate void InfoWriteHandle(string text, MsgEnum MessageIcon);
34 public void MessageShow(string text, MsgEnum MessageIcon)
35 {
36
37 if (this.lvwInfo.InvokeRequired)
38 {
39 InfoWriteHandle iw = MessageShow;
40 this.Invoke(iw, new object[] { text, MessageIcon });
41 }
42 else
43 {
44 try
45 {
46 if (text != "")
47 {
48 string strInfo = DateTime.Now.ToString() + " " + text;
49 if (MessageIcon >= 0)
50 {
51 ListViewItem objItem = new ListViewItem();
52 objItem.Text = strInfo;
53 objItem.ImageIndex = (int)MessageIcon;
54 this.lvwInfo.Items.Add(objItem);
55 this.lvwInfo.Items[this.lvwInfo.Items.Count - 1].EnsureVisible();
56 }
57 }
58
59
60 ItmeCountCheck();
61 }
62 catch (System.Exception ex)
63 {
64 Console.WriteLine(ex.ToString());
65 }
66 }
67 }
68
69
70 /**//// <summary>
71 /// 清空显示信息
72 /// </summary>
73 private delegate void ClearInfoHandle();
74 public void ClearInfo()
75 {
76 if (this.lvwInfo.InvokeRequired)
77 {
78 ClearInfoHandle clr = new ClearInfoHandle(ClearInfo);
79 this.Invoke(clr, null);
80 }
81 else
82 {
83 this.lvwInfo.Items.Clear();
84 }
85
86 ItmeCountCheck();
87 }
88
89 /**//// <summary>
90 /// 检测LISTVIEW的ITEM个数
91 /// </summary>
92 private void ItmeCountCheck()
93 {
94 if (this.lvwInfo.Items.Count > 0)
95 {
96 this.cmnuExportInfo.Enabled = true;
97 }
98 else
99 {
100 this.cmnuExportInfo.Enabled = false;
101 }
102 }
103
104 /**//// <summary>
105 /// 写记录文件
106 /// </summary>
107 public void ExportToTxt()
108 {
109 if (this.SaveInfo.ShowDialog() == DialogResult.OK)
110 {
111 if (this.lvwInfo.Items.Count > 0)
112 {
113 try
114 {
115 string FileNmae = this.SaveInfo.FileName; //+ ".txt";
116 StreamWriter sw;
117 if (File.Exists(FileNmae))
118 {
119 sw = File.AppendText(FileNmae);
120 }
121 else
122 {
123 sw = File.CreateText(FileNmae);
124 }
125
126 sw.WriteLine("====================记录信息====================" );
127 for (int i = 0; i < lvwInfo.Items.Count; i++)
128 {
129 sw.WriteLine(lvwInfo.Items[i].Text.ToString());
130 }
131 sw.Close();
132 MessageShow("信息导出成功", MsgEnum.Infomation);
133 }
134 catch (System.Exception ex)
135 {
136 MessageShow("信息导出失败,具体原因参看系统日志", MsgEnum.Error);
137 }
138
139 }
140 }
141 }
142 #endregion
143
144 private void cmnuExportInfo_Click(object sender, EventArgs e)
145 {
146 this.ExportToTxt();
147 }
148 }
149
150
151}
152
2 using System.Collections;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Windows.Forms;
6 using System.IO;
7
8
9 namespace ProCtrlLib
10 {
11 /**//// <summary>
12 /// 描述:采用LISTVIEW形式加载消息
13 /// 作者:ForrestSun
14 /// 日期: 2006-7-17
15 /// </summary>
16
17 [ToolboxBitmap(typeof(ProMessageBox), "ProMessageBox")]
18 public partial class ProMessageBox : UserControl
19 {
20
21 public ProMessageBox()
22 {
23 InitializeComponent();
24 }
25
26
27 private void cmnuClearInfo_Click(object sender, EventArgs e)
28 {
29 ClearInfo();
30 }
31
32 function#region function
33 delegate void InfoWriteHandle(string text, MsgEnum MessageIcon);
34 public void MessageShow(string text, MsgEnum MessageIcon)
35 {
36
37 if (this.lvwInfo.InvokeRequired)
38 {
39 InfoWriteHandle iw = MessageShow;
40 this.Invoke(iw, new object[] { text, MessageIcon });
41 }
42 else
43 {
44 try
45 {
46 if (text != "")
47 {
48 string strInfo = DateTime.Now.ToString() + " " + text;
49 if (MessageIcon >= 0)
50 {
51 ListViewItem objItem = new ListViewItem();
52 objItem.Text = strInfo;
53 objItem.ImageIndex = (int)MessageIcon;
54 this.lvwInfo.Items.Add(objItem);
55 this.lvwInfo.Items[this.lvwInfo.Items.Count - 1].EnsureVisible();
56 }
57 }
58
59
60 ItmeCountCheck();
61 }
62 catch (System.Exception ex)
63 {
64 Console.WriteLine(ex.ToString());
65 }
66 }
67 }
68
69
70 /**//// <summary>
71 /// 清空显示信息
72 /// </summary>
73 private delegate void ClearInfoHandle();
74 public void ClearInfo()
75 {
76 if (this.lvwInfo.InvokeRequired)
77 {
78 ClearInfoHandle clr = new ClearInfoHandle(ClearInfo);
79 this.Invoke(clr, null);
80 }
81 else
82 {
83 this.lvwInfo.Items.Clear();
84 }
85
86 ItmeCountCheck();
87 }
88
89 /**//// <summary>
90 /// 检测LISTVIEW的ITEM个数
91 /// </summary>
92 private void ItmeCountCheck()
93 {
94 if (this.lvwInfo.Items.Count > 0)
95 {
96 this.cmnuExportInfo.Enabled = true;
97 }
98 else
99 {
100 this.cmnuExportInfo.Enabled = false;
101 }
102 }
103
104 /**//// <summary>
105 /// 写记录文件
106 /// </summary>
107 public void ExportToTxt()
108 {
109 if (this.SaveInfo.ShowDialog() == DialogResult.OK)
110 {
111 if (this.lvwInfo.Items.Count > 0)
112 {
113 try
114 {
115 string FileNmae = this.SaveInfo.FileName; //+ ".txt";
116 StreamWriter sw;
117 if (File.Exists(FileNmae))
118 {
119 sw = File.AppendText(FileNmae);
120 }
121 else
122 {
123 sw = File.CreateText(FileNmae);
124 }
125
126 sw.WriteLine("====================记录信息====================" );
127 for (int i = 0; i < lvwInfo.Items.Count; i++)
128 {
129 sw.WriteLine(lvwInfo.Items[i].Text.ToString());
130 }
131 sw.Close();
132 MessageShow("信息导出成功", MsgEnum.Infomation);
133 }
134 catch (System.Exception ex)
135 {
136 MessageShow("信息导出失败,具体原因参看系统日志", MsgEnum.Error);
137 }
138
139 }
140 }
141 }
142 #endregion
143
144 private void cmnuExportInfo_Click(object sender, EventArgs e)
145 {
146 this.ExportToTxt();
147 }
148 }
149
150
151}
152
代码