最近打开的文件的ListView

时间:2017-06-24 08:56:10

标签: c# winforms listview button richtextbox

我正在做一个文本编辑器。如何在RichTextBox的{​​{1}}中显示上次打开的文件列表?您也可以单击ListView字符串并打开该文件。像打开文件的历史。使用ListView(下面的代码)打开文件。

Button

1 个答案:

答案 0 :(得分:1)

我这样做最简单的方法是将所有打开的文件存储在一个设置字符串中,并使用像\ n这样的分隔符存储该字符串中所有最近打开的文件(我使用这个,因为你不能将它包含在一个名字中,所以没有错误扔了)。

例如,设置字符串就像这样存储

"C:\my file1\nC:\myFile2\nC:\my file 3"

将新文件添加到列表

MyApp.Properties.Settings.recents = MyApp.Properties.Settings.recents + "\n" + ofd.FileName;
MyApp.Properties.Settings.Default.Save();

然后你拆分它并为每次出现使用forloop来生成一个像这样的新listview项目

string[] recentFiles = MyApp.Properties.Settings.recents.split('\n');
foreach (string recentItem in recentFiles) { MyListView.add(recentItem); }
相关问题