使用C#中的菜单项处理Usercontrol [英] Handling Usercontrol with menu items in C#

查看:77
本文介绍了使用C#中的菜单项处理Usercontrol的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好开发者:

我是C#编程的新手,我有一个关于以Win形式处理Usercontrol的问题.我已经开始了新项目,在其中添加了菜单栏.

菜单具有以下项目列表:

新会员
修改会员
删除会员


我为每个菜单项添加了三个usercontrol并将它们命名为:

NewMember_UserControl
ModifyMember_UserControl
DeleteMember_UserControl


现在我要做的是:当我单击新成员菜单"项时,在菜单栏下方的主窗体区域中将显示用户控件"NewMember_UserControl".

请帮助我编写UserControl的菜单甚至处理程序.

Hello Developers:

I am new in programming C#, i have a question about handling Usercontrol in win forms. i have started new project, in it i added a menu strip.

Menu have following List of Item:

New Member
Modify Member
Delete Member


i have add three usercontrol for each of menu items and named them:

NewMember_UserControl
ModifyMember_UserControl
DeleteMember_UserControl


Now what i want to do is: when i click on the New Member Menu Item, Usercontrol "NewMember_UserControl" display on the Main form''s area below the menustrip.

Please help me in writing menu even handler for UserControl.

推荐答案

尝试:
NewMember_UserControl nmuc = new NewMember_UserControl();
Controls.Add(nmuc);



严格来说,它可以满足您的要求,但我不禁会以为您真正想要做的是完全不同的东西……



Strictly speaking, it''ll do what you asked for, but I can''t help thinking that what you actually want to do is something quite different altogether...


进一步了解Griff "的绝佳答案,您可能会发现最好有一个单独的MemberControl支持三种模式[newamenddelete],这些模式可以更改启用的字段以及表单产生的操作.
对相同的事物显示相同的控件是一种很好的设计方法.在您的情况下,您需要一个显示成员的控件,该控件无论模式如何都不会改变,并且在后台的行为会稍有不同.
Further to Griff''s excellent answer, you may find it better to have a single MemberControl that supports three modes [new, amend and delete] that changes which fields are enabled and the action resulting from the form.
It is a good design approach to show the same control for the same thing. In your case you want a control that displays a member, that is unchanged irrespective of the mode, that will have slightly different behaviour behind the scene.


这篇关于使用C#中的菜单项处理Usercontrol的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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