如何以最简单的方式在 V 2010Express C# 中创建 MRU?
首先,我是 C# 编程的新手,我需要尽快创建一个简单的 MRU。
好吧,问题是我尝试查看一些在线示例,但是我发现它们有点太令人困惑了......
那么,无论如何,任何人都可以在toolstripmenuitem 中创建“最近使用的”部分,而无需进入那些复杂的部分代码??
例如,我将无法理解这些东西...
注册表项:
KEY_CURRENT_USER\Software\Microsoft\VCExpress\9.0\FileMRUList
代码:
Application.UserAppDataRegistry.DeleteSubKey("MRU", false);
RegistryKey appKey = Application.UserAppDataRegistry.CreateSubKey("MRU");
dictionary
microsoft.win32
我只需要像下面的链接所示的简单内容 http://www.codeproject.com/KB/menus/MRUHandler.aspx
First of all I am a newbie in C# Programming, and I need to create a simple MRU as fast as i could.
Well the thing is I've tried looking at some online examples but however I found them to be quite a bit too confusing...
So is there anyway that anyone can create a "Recently Used" section in the toolstripmenuitem without going into those complicated codes??
E.g I will not be able to understand this stuff...
Registry key:
KEY_CURRENT_USER\Software\Microsoft\VCExpress\9.0\FileMRUList
Code:
Application.UserAppDataRegistry.DeleteSubKey("MRU", false);
RegistryKey appKey = Application.UserAppDataRegistry.CreateSubKey("MRU");
dictionary
microsoft.win32
I will only need something as simple as shown in this link below http://www.codeproject.com/KB/menus/MRUHandler.aspx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么您想创建一个像屏幕截图中那样的子菜单吗?为此,您必须:
1. 将 MRU 存储在文件中
您可能已经声明了一个私有字段来包含您的 MRU,对吧?
每次有人打开一个文件时,您都会将此文件添加到 MRU 的开头,对吧?
现在,当然,当应用程序关闭时,您需要将此 MRU 保存到文件中。让我们在表单的 FormClosed 事件中执行此操作。双击属性中的 FormClosed 事件并编写一些代码,如下所示:
现在我们已将 MRU 保存在文件中。现在显然当应用程序启动时,我们需要再次加载它,因此在表单的 Load 事件中执行类似的操作:
2. 创建菜单项
现在
_mru
包含我们需要为每个文件路径创建一个新的菜单项。我在这里假设您的文件菜单中已经有一个菜单项(屏幕截图中名为“最近使用”的项目),并且它的名称为mnuRecentlyUsed
,并且我们只需要创建子项:现在我们需要的是实际打开文件的方法,我将其称为
OpenRecentFile
:免责声明
除非您理解,否则请不要使用任何此代码并且您确信它是为了实现您的目的而编写的。如果需要做一些稍微不同的事情,我相信您可以自己进行必要的更改。
另外,我相信您会注意到,上面的内容在程序运行时不会更新子菜单。如果您了解上面的代码是如何工作的,那么我相信您将能够自己弄清楚剩下的部分。
So you want to create a submenu like in the screenshot? For this, you will have to:
1. Store the MRU in a file
You will probably have already declared a private field to contain your MRU, right?
Every time someone opens a file, you add this file to the beginning of the MRU, right?
Now, of course when the application closes, you need to save this MRU to a file. Let’s do that in the Form’s FormClosed event. Double-click the FormClosed event in the properties and write some code which looks somewhat like this:
Now we have saved the MRU in a file. Now obviously when the application starts, we need to load it again, so do something like this in the form’s Load event:
2. Create the menu items
Now that
_mru
contains the file paths that we want in our menu, we need to create a new menu item for each. I’ll be assuming here that you already have a menu item in the File menu (the item called “Most Recently Used” in your screenshot) and that it is calledmnuRecentlyUsed
, and that we only need to create sub-items:Now all we need is the method that actually opens a file, which I called
OpenRecentFile
:Disclaimer
Please don’t use any of this code unless you understand it and you are sure that it is written to do what you intended. If it needs to do something slightly different, I’m sure you can make the necessary changes yourself.
Also, I’m sure you will have noticed that the above doesn’t update the sub-menu while the program is running. If you understand how the above code works, then I’m sure you’ll be able to figure out the rest for yourself.
http://www.codeproject.com/Tips/680088 /Recent-Items-Tool-Strip-Menu-Item
这个项目正是您想要的
http://www.codeproject.com/Tips/680088/Recent-Items-Tool-Strip-Menu-Item
This project does exactly what you want