利用LISTVIEW显示进度信息

工作原因,需要将进度信息显示,并可以保存所以写了个小控件,有需要的朋友可以看下
listInfo.jpg
我只做了正确与错误的显示,其它的可以跟据枚举操作
环境: .NET 2.0
  1 None.gif using  System;
  2 None.gif using  System.Collections;
  3 None.gif using  System.ComponentModel;
  4 None.gif using  System.Drawing;
  5 None.gif using  System.Windows.Forms;
  6 None.gif using  System.IO;
  7 None.gif
  8 None.gif
  9 None.gif namespace  ProCtrlLib
 10 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
 11ExpandedSubBlockStart.gifContractedSubBlock.gif    /**//// <summary>
 12InBlock.gif    /// 描述:采用LISTVIEW形式加载消息
 13InBlock.gif    /// 作者:ForrestSun
 14InBlock.gif    /// 日期: 2006-7-17
 15ExpandedSubBlockEnd.gif    /// </summary>

 16InBlock.gif
 17InBlock.gif    [ToolboxBitmap(typeof(ProMessageBox), "ProMessageBox")]
 18InBlock.gif    public partial class ProMessageBox : UserControl
 19ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 20InBlock.gif
 21InBlock.gif        public ProMessageBox()
 22ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 23InBlock.gif            InitializeComponent();
 24ExpandedSubBlockEnd.gif        }

 25InBlock.gif
 26InBlock.gif     
 27InBlock.gif        private void cmnuClearInfo_Click(object sender, EventArgs e)
 28ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 29InBlock.gif            ClearInfo();
 30ExpandedSubBlockEnd.gif        }

 31InBlock.gif
 32ContractedSubBlock.gifExpandedSubBlockStart.gif        function#region function
 33InBlock.gif        delegate void InfoWriteHandle(string text, MsgEnum MessageIcon);
 34InBlock.gif        public void MessageShow(string text, MsgEnum MessageIcon)
 35ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 36InBlock.gif 
 37InBlock.gif            if (this.lvwInfo.InvokeRequired)
 38ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 39InBlock.gif                InfoWriteHandle iw = MessageShow;
 40ExpandedSubBlockStart.gifContractedSubBlock.gif                this.Invoke(iw, new object[] dot.gif{ text, MessageIcon });
 41ExpandedSubBlockEnd.gif            }

 42InBlock.gif            else
 43ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 44InBlock.gif                try
 45ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
 46InBlock.gif                    if (text != "")
 47ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
 48InBlock.gif                        string strInfo = DateTime.Now.ToString() + "   " + text;
 49InBlock.gif                        if (MessageIcon >= 0)
 50ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
 51InBlock.gif                            ListViewItem objItem = new ListViewItem();
 52InBlock.gif                            objItem.Text = strInfo;
 53InBlock.gif                            objItem.ImageIndex = (int)MessageIcon;
 54InBlock.gif                            this.lvwInfo.Items.Add(objItem);
 55InBlock.gif                            this.lvwInfo.Items[this.lvwInfo.Items.Count - 1].EnsureVisible();
 56ExpandedSubBlockEnd.gif                        }

 57ExpandedSubBlockEnd.gif                    }

 58InBlock.gif
 59InBlock.gif                    
 60InBlock.gif                    ItmeCountCheck();
 61ExpandedSubBlockEnd.gif                }

 62InBlock.gif                catch (System.Exception ex)
 63ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
 64InBlock.gif                    Console.WriteLine(ex.ToString());
 65ExpandedSubBlockEnd.gif                }

 66ExpandedSubBlockEnd.gif            }

 67ExpandedSubBlockEnd.gif        }

 68InBlock.gif
 69InBlock.gif
 70ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
 71InBlock.gif        /// 清空显示信息
 72ExpandedSubBlockEnd.gif        /// </summary>

 73InBlock.gif        private delegate void ClearInfoHandle();
 74InBlock.gif        public void ClearInfo()
 75ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 76InBlock.gif            if (this.lvwInfo.InvokeRequired)
 77ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 78InBlock.gif                ClearInfoHandle clr = new ClearInfoHandle(ClearInfo);
 79InBlock.gif                this.Invoke(clr, null);
 80ExpandedSubBlockEnd.gif            }

 81InBlock.gif            else
 82ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 83InBlock.gif                this.lvwInfo.Items.Clear();
 84ExpandedSubBlockEnd.gif            }

 85InBlock.gif
 86InBlock.gif            ItmeCountCheck();
 87ExpandedSubBlockEnd.gif        }

 88InBlock.gif
 89ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
 90InBlock.gif        /// 检测LISTVIEW的ITEM个数
 91ExpandedSubBlockEnd.gif        /// </summary>

 92InBlock.gif        private void ItmeCountCheck()
 93ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 94InBlock.gif            if (this.lvwInfo.Items.Count > 0)
 95ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 96InBlock.gif                this.cmnuExportInfo.Enabled = true;
 97ExpandedSubBlockEnd.gif            }

 98InBlock.gif            else
 99ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
100InBlock.gif                this.cmnuExportInfo.Enabled = false;
101ExpandedSubBlockEnd.gif            }

102ExpandedSubBlockEnd.gif        }

103InBlock.gif
104ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
105InBlock.gif        /// 写记录文件
106ExpandedSubBlockEnd.gif        /// </summary>

107InBlock.gif        public void ExportToTxt()
108ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
109InBlock.gif            if (this.SaveInfo.ShowDialog() == DialogResult.OK)
110ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
111InBlock.gif                if (this.lvwInfo.Items.Count > 0)
112ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
113InBlock.gif                    try
114ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
115InBlock.gif                        string FileNmae = this.SaveInfo.FileName; //+  ".txt";
116InBlock.gif                        StreamWriter sw;
117InBlock.gif                        if (File.Exists(FileNmae))
118ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
119InBlock.gif                            sw = File.AppendText(FileNmae);
120ExpandedSubBlockEnd.gif                        }

121InBlock.gif                        else
122ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
123InBlock.gif                            sw = File.CreateText(FileNmae);
124ExpandedSubBlockEnd.gif                        }

125InBlock.gif
126InBlock.gif                        sw.WriteLine("====================记录信息====================" );
127InBlock.gif                        for (int i = 0; i < lvwInfo.Items.Count; i++)
128ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
129InBlock.gif                            sw.WriteLine(lvwInfo.Items[i].Text.ToString());
130ExpandedSubBlockEnd.gif                        }

131InBlock.gif                        sw.Close();
132InBlock.gif                        MessageShow("信息导出成功", MsgEnum.Infomation);
133ExpandedSubBlockEnd.gif                    }

134InBlock.gif                    catch (System.Exception ex)
135ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
136InBlock.gif                        MessageShow("信息导出失败,具体原因参看系统日志", MsgEnum.Error);
137ExpandedSubBlockEnd.gif                    }

138InBlock.gif
139ExpandedSubBlockEnd.gif                }

140ExpandedSubBlockEnd.gif            }

141ExpandedSubBlockEnd.gif        }

142ExpandedSubBlockEnd.gif        #endregion

143InBlock.gif
144InBlock.gif        private void cmnuExportInfo_Click(object sender, EventArgs e)
145ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
146InBlock.gif            this.ExportToTxt();
147ExpandedSubBlockEnd.gif        }

148ExpandedSubBlockEnd.gif    }

149InBlock.gif
150InBlock.gif   
151ExpandedBlockEnd.gif}

152 None.gif

代码

转载于:https://www.cnblogs.com/forrestsun/articles/452951.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值