且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过单击其他用户控件中的按钮来显示用户控件。

更新时间:2021-10-11 08:21:21

如果调试代码,问题应该是非常明显的:


您创建菜单的新实例,更改其内容,然后扔掉它



您需要显示新的菜单实例,或以某种方式获取现有实例。



我们无法告诉你如何做到这一点,因为我们看不到创建现有实例的代码,你还没有告诉我们什么菜单类是。



例如,如果菜单是一个表单,并且你要显示新实例,你需要调用 panel.Show(); panel.ShowDialog(); 显示它。
If you debug your code, it should be perfectly obvious what the problem is:

You create a new instance of Menu, change its contents, and then throw it away.

You either need to display the new Menu instance, or get hold of an existing instance somehow.

We can't tell you how to do that, because we can't see the code that creates the existing instance, and you haven't told us what the Menu class is.

For example, if Menu is a Form, and you want to show the new instance, you need to call panel.Show(); or panel.ShowDialog(); to show it.