如何以编程方式向菜单栏添加项目 [英] how to add items to menu strip programmingly

查看:92
本文介绍了如何以编程方式向菜单栏添加项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三种形式form1,form2和form3,

但我在另一个类中编写代码

从该类中,我有五个项目item1,item2,item3,item4,item5

现在通过编程,我想将这些项目添加到form1菜单栏中

我会怎么做,但是以相同的形式很明显

但是我必须以其他形式制作

i have three forms form1, form2 and form3,

but i am writing my code in another class

from that class i have five items item1, item2, item3, item4, item5

now by programming i want to add these items in form1 menu strip

how it will done i have done but in the same form it is clear

but i have to make in other form

推荐答案

您当然可以做到.我将向您展示如何查找代码示例,而不是向您展示如何实现.

首先,问问自己?什么不是以编程方式添加菜单项?这不是这样的东西!

即使与设计师一起工作,它也只会生成与以编程方式"执行的代码基本相同的代码.因此,做一个简单的事情:在Designer中添加带有项目的菜单,然后查看生成的代码.不只是菜单-您还需要以编程方式生成所有控件.

—SA
You can do it of course. Instead of showing to you how to do it, I''ll show you how to find a code sample.

First, ask yourself? What is adding menu items not programmatically? This is no such thing!

Even if you''re working with designer, it simply generates essentially the same code you would do "programmatically". So, do a simple thing: add menu with items in designer and look at the generated code. Not just for menu — for all controls you need to generate programmatically.

—SA


如果您具有三种形式,为什么必须以编程方式添加菜单项?只需在设计器中完成并完成即可.我建议这样做是因为根据您的原始问题,无需在代码中添加项目.
If you have three forms, why do you have to add the menu items programatically? Just do it in the designer and be done with it. I''m suggesting this because based on your original question, there''s no need to add items in code.


假设您已经有一个菜单栏,只需获取所需的项目添加一个子菜单,并添加适当配置的MenuItem对象.
Assuming you already have a menu strip, just get the item you want to add a sub-menu to, and add the appropriately configured MenuItem objects.


这篇关于如何以编程方式向菜单栏添加项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆