Click here to Skip to main content
15,867,568 members
Articles / Programming Languages / C#
Tip/Trick

Recent Items Tool Strip Menu Item

Rate me:
Please Sign up or sign in to vote.
4.91/5 (6 votes)
8 Nov 2013CPOL 16.3K   409   1   5
Create menu item that saves recently opened files

Introduction

This class extends the ToolStripMenuItem control to list recent files and store recently opened files in the registry.

Image 1

Using the Code

  • Add the cs file to your project.
  • Add a menuStrip and a RecentToolStripMenuItem to your project

Image 2

  • 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.

C#
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.

C#
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

  • No updates yet

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionUsing it in 64 bit mode Pin
ehsan_ro9-Jun-15 13:18
ehsan_ro9-Jun-15 13:18 
QuestionAdded simple DeleteItem method Pin
Member 76855517-Jan-14 8:21
Member 76855517-Jan-14 8:21 
QuestionHow to add ItemClick event onto Recent Items Tool Strip Menu Item Pin
Member 1039499312-Nov-13 14:30
Member 1039499312-Nov-13 14:30 
AnswerRe: How to add ItemClick event onto Recent Items Tool Strip Menu Item Pin
CarstenDD13-Nov-13 23:59
CarstenDD13-Nov-13 23:59 
GeneralRe: How to add ItemClick event onto Recent Items Tool Strip Menu Item Pin
Member 1039499314-Nov-13 7:59
Member 1039499314-Nov-13 7:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.