Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Context Menu - Event for closing??? 1

Status
Not open for further replies.

csutton

Programmer
Dec 27, 2000
213
US
Hi everyone, I am trying to figure out a way of knowing when a context menu closes (either if the user clicked a menu choice or clicked outside of the box.) I have a timer that fires every couple of seconds, and redraws a grid. However, when the grid gets redrawn, it looses where the mouse clicked and it needs to know the value of the grid column/row that is clicked.

I can get the timer to stop while the menu is displayed, but I need to know when the user does something (no matter what) so I can enable the timer.

Any thoughts, ideas, help??? Thank you!

Chris
 
Hello Chris,
The problem that you are describing can be complicated and easy to solve at the same time [wink].

Basically you can detect that the user clicked on one of the items by adding a line on the event of that menu, for example:

Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
Timer1.Enabled = False
End Sub


Also at your timer you need to check if the menu is visible. Because the context menu does not have any visible property use the MenuItem.Visible instead (this was the triky part ;-) )

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If MenuItem1.Visible Then
'Do Nothing
Exit Sub
End If
End Sub


I hope that this helps,
Moses
 
A search for the MenuItem.Click Event in the help section will tell you what you need for the menu click anyways.
 
Hi Camel - I tried the visible property, but it is showing it is TRUE all of the time, even when the menu is not visible.

I'm at a loss here :)
 
Hello Chris,
Sorry for that I did not test the code before i post it , really stupid of me [tongue], but never the less i came up with a different approatch to solve the problem.

Create a public variable:
Private _Menu As Boolean = False

on the popup of the contextmenu add the following

Private Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextMenu1.Popup
_Menu = True
Timer1.Enabled = False
End Sub


and on the mouse down of your form add:

Private Sub frmPrint_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
If e.Button.Left AndAlso _Menu = True Then
Timer1.Enabled = True
_Menu = False
End If
End Sub


This will "intercept" all the mesages to the form and allow you to check the mouse button pressed and and allow you to enable or disable the timer.

Hope that this helps
Camel

PS: sorry again for the unchecked code (this code is been tested :) )
 
Ok, thanks :) I'll try that! Thank you again for replying back and testing and giving thought. It is greatly appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top