c#怎么通过一个按钮将记事本中的内容读取到列表框中

c#怎么通过一个按钮将记事本中的内容读取到列表框中

通过事件处理,在事件中获取记事本的内容,然后赋值给列表框。

        private void button2_Click(object sender, EventArgs e)
        {
            // 使用FileStream打开文件
            System.IO.FileStream fs = new System.IO.FileStream(@"d:\BugReport.txt", System.IO.FileMode.Open, System.IO.FileAccess.Read);
            // 根据FileStream读到的字节数创建一个数组
            byte[] bytes = new byte[fs.Length];
            // 将文件内容读到数组中
            fs.Read(bytes, 0, bytes.Length);
            // 关闭文件
            fs.Close();
            // 使用指定的编码将二进制数组转成文本
            string txt = System.Text.Encoding.UTF8.GetString(bytes);
            // 将文本内容放到指定的地方
            ..... 自行撰写
        }