当前位置:
编程学习 >
C#/ASP.NET >>
C# 清理Recent文件实例代码
C# 清理Recent文件实例代码如下:
- using System;
- using System.IO;
- using System.Windows.Forms;
- namespace WinFormTemp
- {
- public partial class FormTemp : Form
- {
- public FormTemp()
- {
- InitializeComponent();
- this.HelpButton = true;
- this.MaximizeBox = false;
- this.MinimizeBox = false;
- this.AutoSizeMode = AutoSizeMode.GrowAndShrink; // 禁用手动调整大小。
- this.SizeGripStyle = SizeGripStyle.Hide; // 隐藏调整大小手柄。
- this.StartPosition = FormStartPosition.CenterScreen; // 在桌面居中显示。
- }
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- DirectoryInfo dir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Recent));
- foreach (FileInfo info in dir.GetFiles("*.lnk"))
- {
- info.Delete();
- }
- System.Diagnostics.Process.Start(dir.FullName);
- }
- protected override void OnHelpButtonClicked(System.ComponentModel.CancelEventArgs e)
- {
- base.OnHelpButtonClicked(e);
- e.Cancel = true;
- FileInfo info = new FileInfo("Clear.bat");
- if (info.Exists)
- info.Attributes = FileAttributes.Normal;
- using (StreamWriter sw = info.CreateText())
- {
- sw.WriteLine("@echo off");
- sw.Write(@"del /f /s /q ""{0}""", Environment.GetFolderPath(Environment.SpecialFolder.Recent));
- }
- System.Diagnostics.Process.Start(info.DirectoryName);
- }
- }
- }
补充:软件开发 , C# ,