Context menu and notifyicon - event not firing?

R

riggs

Hi, I've got a simple program that contains a windows form with 3 command
buttons on. The project also includes a notifyicon and a context menu. The
context menu has 3 menu items (mirroring the 3 command buttons), with each
menu item firing the corresponding command buttons performclick event (eg.
on selecting menuitem1, fires the command1.performclick event).
Problem is that occassionally, selecting the menuitems does nothing. Any
ideas? Would it be better to place the commandbutton code into seperate
procedures and call these from the menu and commandbuttons?

Mark
 
H

Herfried K. Wagner [MVP]

* "riggs said:
Hi, I've got a simple program that contains a windows form with 3 command
buttons on. The project also includes a notifyicon and a context menu. The
context menu has 3 menu items (mirroring the 3 command buttons), with each
menu item firing the corresponding command buttons performclick event (eg.
on selecting menuitem1, fires the command1.performclick event).
Problem is that occassionally, selecting the menuitems does nothing. Any
ideas? Would it be better to place the commandbutton code into seperate
procedures and call these from the menu and commandbuttons?

Does this sample work for you?

<http://www.mvps.org/dotnet/dotnet/samples/windowsandforms/downloads/SimpleNotifyIcon.zip>

Does the code work if you do not use 'PerformClick'?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Dilbert's words of wisdom #18: Never argue with an idiot. They drag you down
to their level then beat you with experience.
 
M

Mark Harris

Herfried K. Wagner said:
Does the code work if you do not use 'PerformClick'?

Hi Herfried, I added a bit of code to one of my menu items, so that it would
display a messagebox before performing the 'performclick' :

Private Sub mnuupdate_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs) Handles mnuupdate.Click
MessageBox.Show("hello")
cmdupdate.PerformClick()
End Sub

The messagebox was displayed, but the cmdupdate code was not executed.

Mark
 
H

Herfried K. Wagner [MVP]

* "Mark Harris said:
Hi Herfried, I added a bit of code to one of my menu items, so that it would
display a messagebox before performing the 'performclick' :

Private Sub mnuupdate_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs) Handles mnuupdate.Click
MessageBox.Show("hello")
cmdupdate.PerformClick()
End Sub

The messagebox was displayed, but the cmdupdate code was not executed.

Add the code from 'cmdUpdate_Click' to a separate procedure. Then call
this procedure from the button's 'Click' event handler and
'mnuupdate_Click' instead of using 'PerformClick'.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Dilbert's words of wisdom #18: Never argue with an idiot. They drag you down
to their level then beat you with experience.
 
M

Mark Harris

Herfried K. Wagner said:
Add the code from 'cmdUpdate_Click' to a separate procedure. Then call
this procedure from the button's 'Click' event handler and
'mnuupdate_Click' instead of using 'PerformClick'.

That does the trick.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top