Solved

Hiding/disabling context menu on mouseenter event

Posted on 2006-10-24
3
310 Views
Last Modified: 2008-02-01
Hello

I have 2 buttons index_futures and index_options...index_futures_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(index_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(index_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
0
Comment
Question by:jbajaj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Expert Comment

by:DjDezmond
ID: 17794364
Im not sure what you mean? You want to hide the context menu? Then delete the code from the sub...? You have posted no code for your mouse_enter event?

Can you explain again?
0
 
LVL 9

Accepted Solution

by:
Naveen Swamy earned 500 total points
ID: 17795015
0
 

Author Comment

by:jbajaj
ID: 17827281
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.AddMessageFilter(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.IContainer

 
#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.Message) As Boolean _
        Implements System.Windows.Forms.IMessageFilter.PreFilterMessage

        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
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question