开发者

C# WinForm MenuStrip Event doesn't seem to fire

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


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜