FileStream aFile = new FileStream(filename, FileMode.Open);
                StreamReader sr = new StreamReader(aFile, System.Text.Encoding.GetEncoding("gb2312"));                string strLine;                listView1.BeginUpdate();
                ListViewItem lvCodeNum;
                ListViewItem.ListViewSubItem lvCode;                for (int i = 0; sr.Peek() > -1; i++)
                {
                    strLine = sr.ReadLine();                    lvCodeNum = new ListViewItem();
                    lvCodeNum.Text = Convert.ToString(i+1);
                    listView1.Items.Add(lvCodeNum);                    lvCode = new ListViewItem.ListViewSubItem();
                    lvCode.Text = strLine;                    strLine = strLine.Replace("\t", "@");                    lvCodeNum.SubItems.Add(lvCode);                    
                }
                listView1.EndUpdate();
我是把读入的源代码放入ListView来一行行显示的源代码里肯定有很多注释,但是奇怪的是,我的如上代码读进来,竟然注释直接接在源代码之后了,tab被自动过滤掉了,很奇怪想问下如何才能在ListView里实现用制表位tab对齐?跟打开文本格式的源代码一样的tab对齐效果?

解决方案 »

  1.   

            string filename = aFileName;                        //文件名
            bool isA = true;                                      //A布尔变量
            bool isB = true;                              //B布尔变量
            bool isC = true;                            //C布尔变量
            bool isD = true;                            //D布尔变量。true表示1;false表示2
    就比如这样的代码好了。代码中的空格是tab实现的,不是手动空格实现的我发现似乎ListView天生忽略tab
    我现在是这么相的
    查找每一行的注释关键字符 ";"
    发现分号,就把后面的内容列入个substring,然后add第三列ListView,填充抽取出来的substring但是代码还没实现