Click here to Skip to main content
15,886,422 members
Articles / Programming Languages / XML

MRU Menu Class

Rate me:
Please Sign up or sign in to vote.
4.00/5 (9 votes)
8 May 2004CPOL1 min read 56.4K   323   26   3
MRU Menu class is basically an ArrayList that will automatically populate a MenuItem in a MainMenu control. It will display the 5 most recent entries and exposes a Click event for you to respond to. You can also save the list to a file with the provided properties.

Sample Image - mruDemo.jpg

Introduction

I am currently working on a couple of programs which need a Most Recently Used files list in the MainMenu. Instead of coding this into each application, I decided to create a reusable class to handle this task for me.

Now, after adding the class to my project, all I have to do is add new file paths as needed, and the MruList class adds the appropriate file paths to the MenuItem I specified.

Declarations

The following needs to be declared to initialize the MRU list:

VB
Public WithEvents theList As CjsDen.MruList

We need to add the initialization of the list to the form's load event:

VB
Private Sub Form_Load(ByVal sender As Object,_
         ByVal e As System.EventArgs) Handles MyBase.Load
    'we need to initialize the mrulist in the forms load event
    theList = New CjsDen.MruList(mnuFileRecent)

End Sub

We also need to add code to handle the MruList's click event:

VB
Public Sub MruFileOpen(ByVal mruPath As String)_
                      Handles theList.mru_click
        'Add code to handle here
        'mruPath returns the string of the clicked menuItem
        'no matter which one is clicked
End Sub

How to Use the MRU List

Now, all we have to do is add file paths to the MRU list:

VB
theList.AddNewFile("c:\myDocument.txt")

If you want to save the list, you can access it with any of the following properties:

  • MruListArray
  • MruPath1
  • MruPath2
  • MruPath3
  • MruPath4
  • MurPath5

Conclusion

This is a very simple way to automate adding a MRU Menu into a number of projects quickly. I have looked this over several ways and have come across no side effects, but if you find anything buggy, let me know.

License

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


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

Comments and Discussions

 
GeneralMRU List Pin
George Hendrickson11-Nov-07 11:48
professionalGeorge Hendrickson11-Nov-07 11:48 
GeneralRe: MRU List Pin
chad_ross11-Nov-07 15:09
chad_ross11-Nov-07 15:09 
GeneralRe: MRU List Pin
Didier Stevens30-Nov-07 3:05
Didier Stevens30-Nov-07 3:05 

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.