Solved

Hiding/disabling context menu on mouseenter event

Posted on 2006-10-24
3
308 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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

856 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