Why the click event doesn't work in my menu project?

DevilAkuma

Active member
Joined
Oct 24, 2005
Messages
37
Programming Experience
Beginner
Hello!

I have a little problem. I've added a MainMenu to my project. The typical 'File' menu... I want to show/hide some MenuItems that have been added to this MainManu. So I've done double click in 'File' (in the design view) and a new function handling the Click event.
The problem appears when I test my project. I click in the menu 'File' and the pop-up menu appears, but the code is not executed!

Any idea!

Thanks in advance.
 
I don't think that the code helps you, but... Here is it!

This is my function created by double click on the first menuItem of my MainMenu. I have a breakpoint inside, but doesn't stop anyway :(
VB.NET:
    Private Sub Menu_File_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Menu_File.Click
    Menu_SaveAs.Enabled = False
End Sub


Thanks in advance
 
Just a random point: That isnt actually a function since the method itself does not return any values. What you have there is a procedure.

I just tested this out now. I built a menu like yours and, initially, the SaveAs item didnt disable. Which is weird, so I added a messagebox to make sure the event fired. It did. Ever since the SaveAs has disabled perfectly. I tested it with an entirely new app and it worked fine as well.

What you should do instead of having it in the Click event, have it in the DropDownOpening event.

Private Sub Menu_File_DropDownOpening(ByVal sender As Object, ByVal e As System.EventArgs) Handles Menu_File.DropDownOpening
Me.Menu_SaveAs.Enabled = False
End Sub

This way the button is disabled immediately. If you use the Click event then the menu opens and you can actually see the SaveAs item go from enabled to disabled. It might actually be the fact that the Click event was used, that the SaveAs item didnt disable properly.

If you still have problems then let us know.
 
Why would you ever want something to happen on the Click event of a top level menu item? The sole purpose of a top-level menu item is to give you access to the drop down items. It should only be the leaf items for which you handle the Click event. Any items that have children should not be having their Click event handled.
 
Back
Top