|
Imports MruSampleVB.CMRmedia.MRUMenu
Public Class Form1
''' <summary>
''' Declare the MRU List so we can capture its events and initialize it
''' </summary>
''' <remarks></remarks>
Public WithEvents mruList As CMRmedia.MRUMenu
''' <summary>
''' FormClosing is used to save the MRU list to persisted file before closing the application
''' </summary>
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
mruList.Save()
End Sub
''' <summary>
''' Form Load is used to initialize the MRU Menu and set any optional properties
''' </summary>
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Initialize MRU list and associate the MenuItem to use as the Recent Files menu
mruList = New CMRmedia.MRUMenu(RecentToolStripMenuItem, Me)
'Optionally you can set your own file path for the MRU list to be saved and loaded from
'mruList.FileName = "x:\Path\To\My\File.xml"
'Optinally you can set the max number of items in the list
mruList.MaxItems = 3
'Optionally you can set the max width of a MRU item
'mruList.Width = 50
'Optionally you can hide/show a "Clear Recent Items" option in the MRU list
'The default is to show it
'mruList.ShowClearRecent() = True
'Optionally you can turn off file validation when loading MRU list from file
'mruList.Validate = False
'Optionally you can turn on Relative Path storage for use with portable applications (USB apps)
'mruList.StoreRelativePaths = True
'Loads the MRU list for persisted file if it exists
mruList.Load()
End Sub
Private Sub QuitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitToolStripMenuItem.Click
Application.Exit()
End Sub
''' <summary>
''' Sample File Open function to simulate handling a file
''' </summary>
Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
OpenFileDialog1.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
Dim rslt As DialogResult = OpenFileDialog1.ShowDialog()
If rslt = Windows.Forms.DialogResult.OK Then
TextBoxOpenFile.Text = OpenFileDialog1.FileName
mruList.AddItem(OpenFileDialog1.FileName)
End If
End Sub
''' <summary>
''' Handles the MRU Menu mruItemClick event
''' </summary>
''' <param name="mruPath">Path of the Menu Item that was clicked</param>
''' <remarks></remarks>
Private Sub MruFileClicked(ByVal mruPath As String) Handles mruList.mruItemClick
MsgBox(mruPath)
Me.Select()
End Sub
''' <summary>
''' Handles the MRU Menu Error event
''' </summary>
''' <param name="ex">returns the MruException object</param>
''' <remarks></remarks>
Private Sub MruError(ByVal ex As MruException) Handles mruList.MruError
Dim str As String = "Error: " & ex.ErrorType.ToString & vbCr
str += "Message: " & ex.message & vbCr
str += "Inner Exception: " & ex.innerException
MsgBox(str, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "MRU Menu Error")
End Sub
End Class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.