Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4271144
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:24:08+00:00 2026-05-21T07:24:08+00:00

I am creating a program using Visual Basic 2010 Express . I want to

  • 0

I am creating a program using Visual Basic 2010 Express.

I want to make a Sub handling both MouseHover and MouseLeave events. Is this possible? And if possible, how do I differ between MouseHover event and MouseLeave event?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:24:09+00:00Added an answer on May 21, 2026 at 7:24 am

    Yes, the same method can handle multiple events, as long as they have compatible signatures. Since both the MouseHover and MouseLeave events have identical method signatures, this is easy.

    By method signatures, of course, I mean the arguments that are passed in. For example, here are the signatures for a method that handles both of those events:

    Sub MouseHoverHandler(ByVal sender As Object, ByVal e As System.EventArgs)
    Sub MouseLeaveHandler(ByVal sender As Object, ByVal e As System.EventArgs)
    

    Since those are identical, the same method can handle both events. All you have to do is add the names of both events after the Handles keyword, separating them with a comma. For example:

    Private Sub MegaHandler(ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles myControl.MouseHover, myControl.MouseLeave
    

    But, alas, that does make it impossible to distinguish between the events, as the same handler will be called for both. This is often convenient when you want to execute identical code and don’t care which individual event was raised.

    It is not a good option when you need to distinguish between the events. But there’s absolutely nothing wrong with defining multiple event handler methods. It won’t affect the performance of your application.


    Another option you could consider is attaching stub methods as the handlers for both of those events, and have those stubs call out to another method that does the actual work. Because each event would have its own individual handler, you would be able to determine which event was raised, and pass that information as a parameter to your worker method. Maybe an explanation would be clearer:

    Private Sub MouseHoverHandler(ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles myControl.MouseHover
    
        ' Call the method that does the actual work
        DoMouseWork(sender, e, True)    
    End Sub
    
    Private Sub MouseLeaveHandler(ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles myControl.MouseHover
    
        ' Call the method that does the actual work
        DoMouseWork(sender, e, False)    
    End Sub
    
    Private Sub MegaMouseHandler(ByVal sender As System.Object, ByVal e As System.EventArgs, _
                                 ByVal isHover As Boolean)
        ' Do the appropriate work to handle the events here.
    
        ' If the isHover parameter is True, the MouseHover event was raised.
        ' If the isHover parameter is False, the MouseLeave event was raised.
     End Sub
    

    Bonus points for recognizing that specifying the type of event would be best implemented by passing an enum value to the mega-handler method, instead of a Boolean value. (Enums make your source code much more descriptive; you have to examine the signature of the MegaMouseHandler method to know what the Boolean parameter represents.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a program that will be installed using the .net installer project.
I am creating object-detection program on Mac. I want to use iSight in manual
While creating a file synchronization program in C# I tried to make a method
I'm creating a setup project using Visual Studio 2008 and I was wondering if
I am creating windows installer project using Visual Studio 2005. Is there an option
I am creating a program with multiple threads using pthreads. Is sleep() causing the
I am creating a program that needs to store the user's data in encrypted
Let's say I'm creating a program in C that needs to use a tempfile.
I have been tasked with creating a program that will generate an amortization schedule.
I have been tasked with creating a program what will create take files in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.