C# WinForm MenuStrip 事件似乎没有触发

发布于 2024-08-22 23:53:47 字数 569 浏览 12 评论 0原文

我不做太多WinFom开发,所以我对MenuStrip控件不太熟悉。我已在表单中添加了一个菜单条,并向其中添加了 (1) 项。所有这一切都是通过设计师完成的。

所以我有实用程序 ->下载实用程序。当我双击设计器中的“下载”时,会为我创建一个事件处理程序。

    private void downloadUtilityToolStripMenuItem_Click(object sender, System.EventArgs e)
        {

             MessageBox.Show("Ding!");

        }

更新:

我注意到我的表单构造函数中的 IntializeComponent() 似乎从未运行过。我在构造函数中放置了一个断点,但它从未命中。我重构了此表单,将名称从默认值 (form1) 更改为“main”。我认为这就是问题所在,但我不明白为什么。所有 form1 参考似乎都已更新。我用 IDE 做了这个。

当我调试这个应用程序时,我似乎永远无法触发这个事件。我在这里缺少什么?

-缺口

I don't do much WinFom development so I am not too familiar with the MenuStrip control. I have added a menu strip to my form and added (1) item to it. All of this was done using the designer.

So I have Utilities -> Download Utility. When I double click on 'Download' in the designer an event handler is created for me.

    private void downloadUtilityToolStripMenuItem_Click(object sender, System.EventArgs e)
        {

             MessageBox.Show("Ding!");

        }

UPDATE:

I noticed that the IntializeComponent() in the constructor of my form never seems to be run. I have placed a breakpoint in the constructor and it never hits. I refactored this form to change the name from the default (form1) to 'main'. I assume this is the problem but I don't see why. All of the form1 references seemed to have been updated. I did this with the IDE.

When I debug this application I can never seem to get this event to fire. What am I missing here?

-Nick

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

朦胧时间 2024-08-29 23:53:47

检查菜单项的属性页(在事件下 - 单击闪电图标),如果 Click 事件有处理程序。

Check on the property page of the menu item (under events - click the lightning icon) if the Click event has a handler.

风筝在阴天搁浅。 2024-08-29 23:53:47

检查:

  • 菜单的属性窗口,单击相关菜单项以获取“下载”
  • 单击“闪电螺栓”,这是属性窗口顶部下方的一个小图标,如果将鼠标悬停在它上面,它将显示工具提示中的“事件”。
  • 向下滚动并在“操作”下查找“单击事件”,双击它,让 VS 自动为您填写事件处理程序

双击表单设计器中的菜单项,这将是默认的到菜单项的点击事件并填写“下载”菜单项的代码,即 MessageBox.Show("Ding");

希望这有帮助,
此致,
汤姆.

Check:

  • Properties Window for the menu, click on the menu item in question for the 'Download'
  • Click on the 'Lightening Bolt', a small icon below the top of the Properties Window, if you were to mouse over it, it would display 'Events' in the tooltip.
  • Scroll down and look for the 'Click Event' under Actions, double click it, to let VS automatically fill in the event handler for you

OR

Double click on the menu item within the Forms Designer, that will default to the menu item's click event and fill in the code for the 'Download' Menu item, i.e. MessageBox.Show("Ding");

Hope this helps,
Best regards,
Tom.

无言温柔 2024-08-29 23:53:47

我成功了。显然在调试项目时它没有重建。重构我的表单名称后,有必要“重建”解决方案。现在我的所有活动都按预期进行。感谢您的帮助。

I got it working. Apparently when debugging the project it wasn't rebuilding. After refactoring the name of my form it was necessary to 'Rebuild' the solution. Now all over my events work as they should. Thanks for the help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文