C# WinForm MenuStrip 事件似乎没有触发
我不做太多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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查菜单项的属性页(在事件下 - 单击闪电图标),如果 Click 事件有处理程序。
Check on the property page of the menu item (under events - click the lightning icon) if the Click event has a handler.
检查:
或
双击表单设计器中的菜单项,这将是默认的到菜单项的点击事件并填写“下载”菜单项的代码,即
MessageBox.Show("Ding");
希望这有帮助,
此致,
汤姆.
Check:
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.
我成功了。显然在调试项目时它没有重建。重构我的表单名称后,有必要“重建”解决方案。现在我的所有活动都按预期进行。感谢您的帮助。
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.