Introduction
This class extends the ToolStripMenuItem
control to list recent files and store recently opened files in the registry.
Using the Code
- Add the cs file to your project.
- Add a
menuStrip
and a RecentToolStripMenuItem
to your project
- Add an
ItemClick
event to set what happens when an item in the list is clicked - Add
recentToolStripMenuItem.UpdateList();
after InitializeComponent();
in the function Form1()
- Use
recentToolStripMenuItem.AddRecentItem(pathToFile);
anytime you save or open a file to add it to the list
You can change the maximum number of items. The default is 5
.
recentToolStripMenuItem.MaxItems = 5;
You can change the registry key the recent list is saved in. The default is HKEY_CURRENT_USER\Software\{Application.CompanyName}\{Application.ProductName}\Recent
.
recentToolStripMenuItem.Key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey
("whatever\\key\\you\\want");
Company Name and Product Name can be changed in the solution properties. Click on the button [Assembly Information].
Points of Interest
If you use AddRecentItem()
for a file that is already in the list, it automatically moves it to the top of the list.
History