【问题标题】:MainMenu in winforms - onclick function is not being invokedWinforms 中的 MainMenu - 未调用 onclick 函数
【发布时间】:2012-10-11 20:52:55
【问题描述】:

在我的 Designer.cs 代码中,我有一个 MainMenu,例如

this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);    
this.menuItemWeigh = new System.Windows.Forms.MenuItem();

//then
this.menuItemWeigh.Index = 0;
this.menuItemWeigh.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemWeighReceived,
this.menuItemWeighFWD,
this.menuItemWeighANV,
this.menuItemWeighFree,
this.menuItemWeighByAdd,
this.menuItemTM,
this.menuItemFM,
this.menuItemWeighPrepQC});
this.menuItemWeigh.OwnerDraw = true;
this.menuItemWeigh.Text = "Main Menu";
this.menuItemWeigh.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.DrawCustomMenuItem);
this.menuItemWeigh.Click += new System.EventHandler(this.menuItemWeigh_Click);

当我单击 menuItemWeigh 时,不会调用 onclick 例程。

如果我点击 menuItemWeigh 的左侧,我会得到子菜单;单击 menuItemWeigh 的任何其他区域都不会产生任何结果。

如何确保当用户单击 menuItemWeigh 上的任意位置时显示子菜单?我正在考虑实现 onclick 例程,但它根本没有被调用。

我应该注意此菜单控件的特定内容吗?

【问题讨论】:

  • CSS?它是 winforms。就像在 Windows 应用程序中一样。

标签: c# winforms events menuitem


【解决方案1】:

原来MainMenu 已在 3.5 中停用,MenuStrip 将用于菜单。 MainMenu 仍然有些兼容,但有一些怪癖。

http://www.c-sharpcorner.com/uploadfile/mahesh/menustrip-in-C-Sharp/

【讨论】:

    猜你喜欢
    • 2011-02-08
    • 1970-01-01
    • 2023-03-18
    • 2012-06-26
    • 2011-05-13
    • 2019-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多