Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recent Fie List

Status
Not open for further replies.

ComputersUnlimited

IS-IT--Management
Dec 18, 2013
37
US
I am working on a program where I want to add a recent file list, much like MS Office.

I have added a menustrip with a ToolStripMenuItem. I have been able to add a list of recent files to the ToolStripMenuItem. However I am not able to open recent files when clicking on them in the ToolStripMenuItem.

Doing research I learned that I need to use Add Handler, but have not found a easily understandable explanation on how to do this.

Is using Add Handler the best and easiest way to do this, if so how?
Is their a better way to do this, if so how?

Anybody have a good explanation or know of a site that explains it well.

Thank You
 
First, create the handler code for the ToolStripMenuItem's Click event:

Say it's named RecentFilesMenu, so use
Private Sub RecentFilesMenu_Click(Sender as Object, e as EventArgs)
'code here
End Sub

Then, in the form's Load event, put the AddHandler code:

AddHandler ToolStripMenuItem1.Click, AddressOf RecentFilesMenu_Click

Now when you click on the ToolStripMenuItem, the code in RecentFilesMenu_Click will run.

Also, if you're adding a ToolStripMenuItem for each recent file, then you're probably defining and adding them at runtime. To make the ToolStripMenuItem work with the event handler, it has to be defined as WithEvents, like so:

Dim WithEvents ToolStripMenuItem1 As ToolStripMenuItem

If you don't Dim WithEvents, the AddHandler code will fail.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top