当前位置:编程学习 > C#/ASP.NET >>

C# 清理Recent文件实例代码

C# 清理Recent文件实例代码如下:

  1. using System;
  2. using System.IO;
  3. using System.Windows.Forms;
  4. namespace WinFormTemp
  5. {
  6.     public partial class FormTemp : Form
  7.     {
  8.         public FormTemp()
  9.         {
  10.             InitializeComponent();
  11.             this.HelpButton = true;
  12.             this.MaximizeBox = false;
  13.             this.MinimizeBox = false;
  14.             this.AutoSizeMode = AutoSizeMode.GrowAndShrink; // 禁用手动调整大小。
  15.             this.SizeGripStyle = SizeGripStyle.Hide; // 隐藏调整大小手柄。
  16.             this.StartPosition = FormStartPosition.CenterScreen; // 在桌面居中显示。
  17.         }
  18.         protected override void OnLoad(EventArgs e)
  19.         {
  20.             base.OnLoad(e);
  21.             DirectoryInfo dir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Recent));
  22.             foreach (FileInfo info in dir.GetFiles("*.lnk"))
  23.             {
  24.                 info.Delete();
  25.             }
  26.             System.Diagnostics.Process.Start(dir.FullName);
  27.         }
  28.         protected override void OnHelpButtonClicked(System.ComponentModel.CancelEventArgs e)
  29.         {
  30.             base.OnHelpButtonClicked(e);
  31.             e.Cancel = true;
  32.             FileInfo info = new FileInfo("Clear.bat");
  33.             if (info.Exists)
  34.                 info.Attributes = FileAttributes.Normal;
  35.             using (StreamWriter sw = info.CreateText())
  36.             {
  37.                 sw.WriteLine("@echo off");
  38.                 sw.Write(@"del /f /s /q ""{0}""", Environment.GetFolderPath(Environment.SpecialFolder.Recent));
  39.             }
  40.             System.Diagnostics.Process.Start(info.DirectoryName);
  41.         }
  42.     }
  43. }
补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,