启用menustrip项目 [英] Enable menustrip items

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

问题描述

我可以通过以下代码加载子表单并在父级上禁用Menustrip项目:



 Dim ge As New GenerateID 
ge.TopLevel = False
Me.GBempIDcard.Controls.Add(ge)
ge.StartPosition = FormStartPosition.CenterParent
ge.Show()
MenuS.Enabled =假







我可以帮助我点击如何启用menustrip项目在vb的子表单上关闭按钮?



我尝试过:



我试过:



 Private Sub btnexit_Click(sender As Object,e As EventArgs)处理btnexit.Click 
Me。关闭()
empIDcards.MenuS.Enabled = True

结束Sub



但它不启用

解决方案

不要那样尝试 - 你需要父表单的实例让它工作,而孩子甚至不应该知道e父母的存在,更不用说它有一个菜单。



相反,在子表单中创建一个在父表单中处理的事件。然后父母根据需要启用和禁用它自己的菜单。

这听起来很复杂,但它不是,不是真的 - 它只是几行代码。这显示了如何在C#中执行此操作:在两个表单之间传输信息,第2部分:孩子到家长 [ ^ ] - 但原理完全相同,在线转换器如 Telerik Code Converter [ ^ ]如果您无法解决问题,应该会有所帮助。

活动也包含在MSDN上:如何:向班级添加活动 [ ^

I am able to load a child form and disable Menustrip Items on the parent by this code:

Dim ge As New GenerateID
    ge.TopLevel = False
    Me.GBempIDcard.Controls.Add(ge)
    ge.StartPosition = FormStartPosition.CenterParent
    ge.Show()
    MenuS.Enabled = False




Please can someone help me with how to enable menustrip items when i click close button on the child form in vb?

What I have tried:

I tried:

Private Sub btnexit_Click(sender As Object, e As EventArgs) Handles btnexit.Click
       Me.Close()
       empIDcards.MenuS.Enabled = True

   End Sub


But it does not enable

解决方案

Don't try like that - you would need the instance of the parent form to get it to work, and the child shouldn't even know about the existence of a parent, much less that it has a menu.

Instead, create an event in the child form which is handled in the parent. The parent then enables and disables it's own menu as required.
That sounds complicated, but it isn't, not really - it's only a few lines of code. This shows how to do it in C#: Transferring information between two forms, Part 2: Child to Parent[^] - but the principle is exactly the same, and online converters such as Telerik Code Converter[^] should help if you can't work it out.
Events are also covered on MSDN: How to: Add Events to a Class[^]


这篇关于启用menustrip项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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