如何以编程方式将内容添加到菜单条?
我想将文本框中写入的任何内容添加到菜单条中。在文件>我最近的搜索。
我怎样才能以编程方式进行?我是否可以动态分配一个事件处理程序,以便当用户单击该子文件夹中的 X 项目时,文本将复制回文本框?
编辑:如何以编程方式调用文件夹 Busquedas Recientes(如图)
I want to add whatever is written in a textbox to a menustrip. In the File > Recent Searches thing I have.
How can I do programatically? And can I assign an event handler dynamically so that when a user clicks on X item in that subfolder, the text is copied BACK to the textbox?
EDIT: How can I programatically call on the folder Busquedas Recientes (in pic)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过利用事件处理程序中的
object sender
参数来实现此目的。其中大部分内容都在我的脑海中,所以我只是猜测它会编译,但它应该可以帮助您入门。You can do this by taking advantage of the
object sender
parameter in the event handler. Most of this is off the top of my head so I'm only guessing that it will compile but it should get you started.这相当简单。您可以执行以下操作:
随后,如果 Click 事件不起作用(我遇到了无法检测到正确菜单项的问题),您可以向 menuItem 添加“DropDownItemClicked”事件。并获取您单击的项目的文本:
我希望有帮助。
哦,别忘了也删除事件。我忘记对我创建的所有动态菜单执行此操作,结果不知何故耗尽了我一半的内存。 :D
It's rather straight forward. You can do the following:
Subsequently, if the Click event doesn't work (I had trouble where it wouldn't detect the correct menu item), you can add a "DropDownItemClicked" event to the menuItem. and to get the text of the item you clicked you do:
I hope that helps.
Oh and don't forget to remove the Event as well. I forgot to do that with all the dynamic menus I had created and somehow ended up eating half my memory. :D