更新时间: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 ofMenu
, change its contents, and then throw it away.
You either need to display the newMenu
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 theMenu
class is.
For example, ifMenu
is aForm
, and you want to show the new instance, you need to callpanel.Show();
orpanel.ShowDialog();
to show it.