jbajaj
asked on
Hiding/disabling context menu on mouseenter event
Hello
I have 2 buttons index_futures and index_options...index_futu res_cm and index_options_cm are the two context menus assocaited with them
When I 'mouseenter' index_futures index_futures_cm pops up. However now when I enter index_options its associated contextmenu wont pop up i.e no mouseneter event is triggered
Here is the code
Private Sub index_futures_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles index_futures.MouseEnter
index_futures.BackColor = Color.DarkBlue
index_futures.ForeColor = Color.White
index_options.BackColor = Color.WhiteSmoke
index_options.ForeColor = Color.Black
pos = New Point(index_futures.Width + 1)
index_futures_cm.Show(inde x_futures, pos)
' index_futures.BackColor = Color.DarkBlue
' index_futures.ForeColor = Color.White
End Sub
Private Sub index_options_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles index_options.MouseEnter
index_options.BackColor = Color.DarkBlue
index_options.ForeColor = Color.White
index_futures.BackColor = Color.WhiteSmoke
index_futures.ForeColor = Color.Black
pos = New Point(index_options.Width + 1)
index_options_cm.Show(inde x_options, pos)
End Sub
In a nutshell, I want to hide the context menu on mouseenter event and not a mouseclick event.
I know this is against the general implemetation of a menu, but I am trying to replicate a menu similar to the "programs" "documents" seen on the left of the windows
thank you...please let me know asap as this is super urgent....i had posted the thread by mistake in C++ region and there has been enough delay
I have 2 buttons index_futures and index_options...index_futu
When I 'mouseenter' index_futures index_futures_cm pops up. However now when I enter index_options its associated contextmenu wont pop up i.e no mouseneter event is triggered
Here is the code
Private Sub index_futures_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles index_futures.MouseEnter
index_futures.BackColor = Color.DarkBlue
index_futures.ForeColor = Color.White
index_options.BackColor = Color.WhiteSmoke
index_options.ForeColor = Color.Black
pos = New Point(index_futures.Width + 1)
index_futures_cm.Show(inde
' index_futures.BackColor = Color.DarkBlue
' index_futures.ForeColor = Color.White
End Sub
Private Sub index_options_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles index_options.MouseEnter
index_options.BackColor = Color.DarkBlue
index_options.ForeColor = Color.White
index_futures.BackColor = Color.WhiteSmoke
index_futures.ForeColor = Color.Black
pos = New Point(index_options.Width + 1)
index_options_cm.Show(inde
End Sub
In a nutshell, I want to hide the context menu on mouseenter event and not a mouseclick event.
I know this is against the general implemetation of a menu, but I am trying to replicate a menu similar to the "programs" "documents" seen on the left of the windows
thank you...please let me know asap as this is super urgent....i had posted the thread by mistake in C++ region and there has been enough delay
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello
I tried using IMessageFilter to do the same. I still cant . Please find my code below. If I enter button2 I should be able hide the context menu related to button1. Can someone please help asap
Imports System.Text
Imports System
Imports System.Data
Imports System.Drawing
Imports System.Windows.Forms
Public Class Form1
Inherits System.Windows.Forms.Form
Implements IMessageFilter
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
Application.AddMessageFilt er(Me)
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon tainer
#End region
Dim pos As Point
' Discard mouse messages waiting to be processed
'
' This procedure is sometimes useful to prevent VB
' from processing spurious mouse clicks
'This method is called by the system for all messages
Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Messa ge) As Boolean _
Implements System.Windows.Forms.IMess ageFilter. PreFilterM essage
If Not Me.IsDisposed Then
'reset the clock here for any input you would like to test for
Const WM_LBUTTONDOWN = &H201
Const WM_RBUTTONDOWN = &H204
Const WM_KEYDOWN = &H100
Const QS_MOUSEMOVE = &H200
Select Case m.Msg
Case WM_LBUTTONDOWN, WM_RBUTTONDOWN, QS_MOUSEMOVE
resetClock("Mouse")
Case WM_KEYDOWN
resetClock("KeyPress")
'Case QS_MOUSEMOVE
' resetClock("mousemove")
End Select
'pass the message on to the form
Return False
End If
End Function
Private Sub resetClock(ByVal method As String)
'you would actually reset your timer method here
'Just output to debug for illustration
Debug.WriteLine(method & " reset me " & Now & Cursor.Position.X & Cursor.Position.Y)
'MessageBox.Show(method & " reset me " & Now)
' SendKeys.Send("{ESC}")
' WindowFromMouse()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
pos = New Point(Button1.Width + 1)
ContextMenu1.Show(Button1, pos)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.MouseEnter
pos = New Point(Button2.Width + 1)
ContextMenu2.Show(Button2, pos)
End Sub
Private Sub contextMenu1_Popup(ByVal sender As Object, ByVal e As System.EventArgs) Handles ContextMenu1.Popup
End Sub
End Class
I tried using IMessageFilter to do the same. I still cant . Please find my code below. If I enter button2 I should be able hide the context menu related to button1. Can someone please help asap
Imports System.Text
Imports System
Imports System.Data
Imports System.Drawing
Imports System.Windows.Forms
Public Class Form1
Inherits System.Windows.Forms.Form
Implements IMessageFilter
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
Application.AddMessageFilt
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
#End region
Dim pos As Point
' Discard mouse messages waiting to be processed
'
' This procedure is sometimes useful to prevent VB
' from processing spurious mouse clicks
'This method is called by the system for all messages
Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Messa
Implements System.Windows.Forms.IMess
If Not Me.IsDisposed Then
'reset the clock here for any input you would like to test for
Const WM_LBUTTONDOWN = &H201
Const WM_RBUTTONDOWN = &H204
Const WM_KEYDOWN = &H100
Const QS_MOUSEMOVE = &H200
Select Case m.Msg
Case WM_LBUTTONDOWN, WM_RBUTTONDOWN, QS_MOUSEMOVE
resetClock("Mouse")
Case WM_KEYDOWN
resetClock("KeyPress")
'Case QS_MOUSEMOVE
' resetClock("mousemove")
End Select
'pass the message on to the form
Return False
End If
End Function
Private Sub resetClock(ByVal method As String)
'you would actually reset your timer method here
'Just output to debug for illustration
Debug.WriteLine(method & " reset me " & Now & Cursor.Position.X & Cursor.Position.Y)
'MessageBox.Show(method & " reset me " & Now)
' SendKeys.Send("{ESC}")
' WindowFromMouse()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
pos = New Point(Button1.Width + 1)
ContextMenu1.Show(Button1,
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.MouseEnter
pos = New Point(Button2.Width + 1)
ContextMenu2.Show(Button2,
End Sub
Private Sub contextMenu1_Popup(ByVal sender As Object, ByVal e As System.EventArgs) Handles ContextMenu1.Popup
End Sub
End Class
Can you explain again?