Solved

Hiding/disabling context menu on mouseenter event

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

912 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now