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

  • Home
  • SEARCH
  • 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 3611914
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:56:03+00:00 2026-05-18T21:56:03+00:00

how can i know what event was triggered in picturebox in VBnet? in vbnet

  • 0

how can i know what event was triggered in picturebox in VBnet?

in vbnet code:

Private Sub picButton_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles picButton.MouseEnter
    'CODE HERE'
End Sub

Private Sub picButton_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles picButton.MouseLeave
    'CODE HERE'
End Sub

and i want to make it like this:

Private Sub picButtonEVent(ByVal sender As Object, ByVal e As System.EventArgs) Handles picButton.MouseLeave, picButton.MouseEnter
    'CODE HERE'
    'If MouseEnter Then'
        'Code for mouseEnter'
    'ElseIf MouseLeave Then'
        'Code for mouseLeave'
    'End If'
End Sub

i want to know what event was triggered whether it is .MouseEnter or .MouseLeave. the reason why i’m making this is to make the code more categorized according to the object that was used.

  • 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-18T21:56:04+00:00Added an answer on May 18, 2026 at 9:56 pm

    One thing you could do is to create a helper function that takes an additional Enum parameter that you can use to determine the event type, and then you can just enclose the dummy events in a region so you can collapse them. Off-hand, I don’t know of an elegant way to determine what event actually fired from the event itself (that is, without using Reflection…)

    My suggestion:

    Private Sub picButton_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles picButton.MouseEnter
        UniversalEvent(this, e, EventType.MouseEnter)
    End Sub
    
    Private Sub picButton_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles picButton.MouseLeave
        UniversalEvent(this, e, EventType.MouseLeave)
    End Sub
    
    Private Sub UniversalEvent(ByVal sender As Object, ByVal e As System.EventArgs, ByVal eventType As EventType)
        If MouseEnter Then
            'Code for mouseEnter'
        ElseIf MouseLeave Then
            'Code for mouseLeave'
        End If'
    End Sub
    

    Edit:

    As mentioned before, Reflection is a possibility, though not ideal due to the amount of overhead involved (especially in the case of events like these which could be called quite frequently). That being said, I whipped up a working example using Reflection simply to illustrate that it’s possible. (Actually StackTrace, which is what I used, is in System.Diagnostics. Not exactly Reflection but it’s close enough for me…)

    Please don’t send the raptors…

    Public Class Form1
    
        Private Sub PictureBox_Events(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles PictureBox1.MouseLeave, PictureBox1.MouseEnter
    
            Select Case GetEventType(New StackTrace())
                Case EventType.MouseEnter
                    Console.WriteLine("Enter")
                Case EventType.MouseLeave
                    Console.WriteLine("Leave")
                Case Else
                    Console.WriteLine("Dunno")
            End Select
    
        End Sub
    
        Private Function GetEventType(ByRef callStack As StackTrace) As EventType
            'I laugh in the face of NullReferenceExceptions...'
            Dim callerName As String = callStack.GetFrames()(1).GetMethod().Name
    
            If "OnMouseEnter".Equals(callerName, StringComparison.OrdinalIgnoreCase) Then
                Return EventType.MouseEnter
            ElseIf "OnMouseLeave".Equals(callerName, StringComparison.OrdinalIgnoreCase) Then
                Return EventType.MouseLeave
            End If
    
            Return EventType.Dunno
    
        End Function
    
        Enum EventType
            Dunno
            MouseEnter
            MouseLeave
        End Enum
    
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

You can know if the event stack is empty calling the gtk.events_pending() method, but
I know one can add event listener for window.error. However when working with Iframes,
Is there a way I can know who holds a reference to an object?
like in java I have: Class.getSuperClass().getDeclaredFields() how I can know and set private field
So I have an event that can be triggered by a change of the
how can I listen, in an activity, to an event triggered in another activity?
I know I can use watch to bind a callback that will be triggered
I know I can get touch events in my iPhone app. But these touch
We know that a single application instance can use multiple cores and even multiple
As you can know, you can store data against a contact on Android phones.

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.