Having a recent menu list is a nice little feature to add to your apps and it makes them look more polished. VB.NET Private Sub Form1_Load(sender As Object, e As EventArgs) _ĭim fileRecent As New ToolStripMenuItem(item, Nothing, ToolStripMenuItem fileRecent = new ToolStripMenuItem(item, (ByRef target As T, ByVal value As T) As TĬ# private void Form1_Load_1(object sender, EventArgs e) Private Shared Function InlineAssignHelper(Of T) _ While (InlineAssignHelper(strLine, srStream.ReadLine())) _ Private static T InlineAssignHelper(ref T target, T value) (Environment.CurrentDirectory + strLine = "" Now, let’s add the loading of the file names from the file. (tsRecent)ĭim stringToWrite As New StreamWriter(System.Environment _ ()ĭim tsRecent As New ToolStripMenuItem(strItem, Nothing) VB.NET Private Sub SaveRecentFile(strPath As String) Let’s add the logic to save the recent items into a file now.Ĭ# private void SaveRecentFile(string strPath) To get the items, the items first need to be saved into a txt file and later read from that same file. The Queue of string objects will hold all the items present in the current MRU list. VB.NET Dim MRUlist As Queue(Of String) = New Queue(Of String)() This means that the current file name will be written to a certain file, and this file will then be read to get the list of previously opened files.Ĭreate a new Windows Forms project in either VB.NET or C#, and add a menustrip to it, as shown in Figure 1.Īdd the System.IO namespace because we will be working with files.Ĭreate a Queue object to store the MRU items when read. There are various ways, the Registry being the most popular, but sometimes a PC is set up without giving the user account Registry editing capabilities, or limited, so I have opted to make use of file input and output. (new wondered how to create an MRU (Most Recently Used) menu list? Well, in today’s article I will show you a quick way of keeping track of which files were opened and saved so that you can re-open them quicker. This.customizeToolStripMenuItem = new () This.printPreviewToolStripMenuItem = new () / the contents of this method with the code editor. / Required method for Designer support - do not modify #region Windows Form Designer generated code Object sender, ToolStripItemClickedEventArgs e) Private void fileToolStripMenuItem_DropDownItemClicked( called UpdateStatus, which updates the text displayed It passes the ClickedItem object to a utility method This method is the DropDownItemClicked event handler. String msg = String.Format(" selected", item.Text) Private void UpdateStatus(ToolStripItem item) control's Text property to the Text property of the This utility method assigns the value of a ToolStripItem Protected override void Dispose(bool disposing) Your MyMenuStrip will appear at the top of the. Finally remove the original MenuStrip from the project and build the solution. Now, rebuild your MenuStrip, removing code from your project as you add the code to your MyMenuStrip class. Make the first statement in the class: Inherits MenuStrip. Private ToolStripStatusLabel toolStripStatusLabel1 Add a class to your project called MyMenuStrip. Menu item selections are displayed in a StatusStrip control. The following code example demonstrates how to use a MenuStrip control to create a form with a standard menu. There is extensive support for this feature in Visual Studio.Īlso see Walkthrough: Providing Standard Menu Items to a Form. You can provide a standard menu for your forms with the MenuStrip control.
0 Comments
Leave a Reply. |