以前VS项目记录浏览很多,要清除还得打开注册表进行手动清除,很是麻烦,自己为了方便就做了一个清除软件,方便,快速的解决了这一问题,于是给大家分享一下,不足之处还望留言,我会改善。
1.清除VS项目记录,如图:
2.清除VS项目文件记录,如图:
源码实现,参考:
private RegistryKey ProjectKey = null;
private RegistryKey FileKey = null;
private void button1_Click(object sender, EventArgs e)
{
getPKeyValuArray();
}
public void getPKeyValuArray()
{
try
{
listView1.Items.Clear();
RegistryKey hklm = Registry.CurrentUser;
string strVSKey = "";
switch (cbVsList.SelectedIndex)
{
case 0:
strVSKey = "8.0";
break;
case 1:
strVSKey = "9.0";
break;
default:
break;
}
RegistryKey software = hklm.OpenSubKey("Software");
//打开"SOFTWARE/Microsoft/VisualStudio"子键
ProjectKey = software.OpenSubKey("Microsoft", true).OpenSubKey("VisualStudio", true).OpenSubKey(strVSKey, true).OpenSubKey("ProjectMRUList", true);
//打开"ProjectMRUList"子键
string[] arrSubItem = new string[2];
string[] sitekeyValue = ProjectKey.GetValueNames();
//开始遍历由键值字符串数组
int iCount = 0; int iconIndex = 1;
foreach (string site in sitekeyValue)
{
arrSubItem[0] = site;
arrSubItem[1] = ProjectKey.GetValue(site).ToString();
ListViewItem LiItem = new ListViewItem(arrSubItem, iconIndex);
listView1.Items.Insert(iCount, LiItem);
iCount++;
iconIndex++;
}
}
catch { }
}
private void btPDelete_Click(object sender, EventArgs e)
{
if(listView1.FocusedItem==null){ return; }
try
{
string deteleKeyValue = listView1.FocusedItem.Text;
ProjectKey.DeleteValue(deteleKeyValue);
MessageBox.Show("删除成功!");
getPKeyValuArray();
}
catch { }
}
private void btFile_Click(object sender, EventArgs e)
{
getFKeyValueArray();
}
public void getFKeyValueArray()
{
try
{
listView2.Items.Clear();
RegistryKey hklm = Registry.CurrentUser;
string strVSKey = "";
switch (cbVsList.SelectedIndex)
{
case 0:
strVSKey = "8.0";
break;
case 1:
strVSKey = "9.0";
break;
default:
break;
}
RegistryKey software = hklm.OpenSubKey("Software");
//打开"SOFTWARE/Microsoft/VisualStudio"子键
FileKey = software.OpenSubKey("Microsoft", true).OpenSubKey("VisualStudio", true).OpenSubKey(strVSKey, true).OpenSubKey("FileMRUList", true);
//打开"ProjectMRUList"子键
string[] arrSubItem = new string[2];
string[] sitekeyValue = FileKey.GetValueNames();
//开始遍历由键值字符串数组
int iCount = 0; int iconIndex = 1;
foreach (string site in sitekeyValue)
{
arrSubItem[0] = site;
arrSubItem[1] = FileKey.GetValue(site).ToString();
ListViewItem LiItem = new ListViewItem(arrSubItem, iconIndex);
listView2.Items.Insert(iCount, LiItem);
iCount++;
iconIndex++;
}
}
catch { }
}
private void btFDelete_Click(object sender, EventArgs e)
{
if (listView2.FocusedItem == null) { return; }
try
{
string deteleKeyValue = listView2.FocusedItem.Text;
FileKey.DeleteValue(deteleKeyValue);
MessageBox.Show("删除成功!");
getFKeyValueArray();
}
catch { }
}