使用C Sharp在MenuStrip中动态添加MenuItem [英] Adding MenuItems In MenuStrip Dynamically Using C Sharp

查看:70
本文介绍了使用C Sharp在MenuStrip中动态添加MenuItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,
我正在使用c Sharp在我的项目中添加菜单栏..由于我是新用户,所以我对c Sharp的了解不多..请帮我动态添加菜单项在菜单栏中...

我只想在我已经在表单中添加的菜单栏中动态添加菜单项..

问候,
Hassan Tariq

Hi Dear,
I am using c sharp to add menustrip in my project..i did not have much knowledge of c sharp as i am a new user..please do help me out regarding adding the menu items in my menustrip dynamically...

All i want is that to add menuitems dynamically in my menustrip which i''ll already added in my form..

Regards,
Hassan Tariq

推荐答案

通常情况如下:

Generally, it goes like this:

menuStrip1.Items.Add(new ToolStripMenuItem(...));



Google是您的朋友.



Google is your friend.


我希望通过System.Windows.Forms对.NET中的所有问题(例如如何动态……")提供一个一般性的答案.

方法如下:

首先,请理解没有不动态"添加控件的事情.每个控件都是在运行时动态添加的.您可以使用Designer的事实不会改变这个基本而简单的事实.设计器仅有助于编写用于设置表单控件的代码.

因此,您可以回答所有这样的问题:如果您知道如何使用Designer进行操作,而不是通过编码来完成,请使用Designer.完成后,请查看自动生成的代码.它作为表单节点的子节点放置在项目结构的注释中;文件名以"Designer.cs"结尾.阅读此文件,看看情况如何.就这样.

—SA
I would prefer to give you a general answer to all questions like "how to… dynamically" in .NET with System.Windows.Forms.

Here is how:

First, please understand there is no such thing as adding controls "not dynamically". Every control is added during run time, dynamically. The fact your may use Designer does not change this fundamental and simple fact. The Designer only helps to write the code setting up the controls for a form.

Therefore, you can answer all your questions like this: if you know how to do things with Designer, but not by coding, do it with designer. After you do it, look at the auto-generated code; it is placed in the note of the project structure as a child node of the form node; and the file name ends with "Designer.cs". Read this file and see how things were done. That''s it.

—SA


这篇关于使用C Sharp在MenuStrip中动态添加MenuItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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