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 692599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:40:03+00:00 2026-05-14T02:40:03+00:00

I havea a UserControl1 (in witch I have an Label1 ) in Form1 .

  • 0

I havea a UserControl1 (in witch I have an Label1) in Form1. I want to catch the MouseDown event from Label and send it like it was from UserControl.

I do:

Public Class UserControl1
  Shadows Custom Event MouseDown As MouseEventHandler

    AddHandler(ByVal value As MouseEventHandler)
      AddHandler Label1.MouseDown, value
    End AddHandler

    RemoveHandler(ByVal value As MouseEventHandler)
      RemoveHandler Label1.MouseDown, value
    End RemoveHandler

    RaiseEvent(ByVal sender As Object, ByVal e As MouseEventArgs)
      'RaiseMouseEvent(Me, e) ??? '
    End RaiseEvent

  End Event

End Class

However, when I set in the Form1 the UserControl

  Private Sub UserControl11_MouseDown(ByVal sender As System.Object, _ 
      ByVal e As System.Windows.Forms.MouseEventArgs) _ 
          Handles UserControl11.MouseDown

    ' here I have "Label", BUT want "UserControl" '
    MessageBox.Show(sender.GetType.Name)
  End Sub

One detail.. I want that the event should be only on the label, not on the whole userControl.

  • 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-14T02:40:03+00:00Added an answer on May 14, 2026 at 2:40 am

    Why don’t you just handle the event “old school” and delegate it, instead of creating a custom event? Like so:

    ' In the user control: '
    Private Sub Label1_MouseDown(sender As Object, e As MouseEventArgs) _
            Handles Label1.MouseDown
        OnMouseDown(e)
    End Sub
    

    Now when you handle the UserControl.MouseDown event in your form, the sender of the event will be the user control instance.

    If you only want to capture clicks on the label (instead of on the whole user control) then you can override OnMouseDown to test from where the click originates:

    Private m_MouseDownFromLabel As Boolean = False
    
    Private Sub Label1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) _
            Handles Label1.MouseDown
        m_MouseDownFromLabel = True
        OnMouseDown(e)
    End Sub
    
    Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
        If m_MouseDownFromLabel Then
            m_MouseDownFromLabel = False
            MyBase.OnMouseDown(e)
        End If
    End Sub
    

    This should be safe in the face of race conditions since there’s only one UI thread.

    By the way: RaiseMouseEvent cannot be used here since the first argument would have be the MouseDown event property. However, this property cannot be accessed from derived classes, only inside the Control class itself. I don’t know why RaiseMouseEvent isn’t private itself, instead of being protected, when it can’t be used from derived classes anyway.

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

Sidebar

Related Questions

I have 10 custom usercontrol's with ID's usercontrol1, usercontrol2, usercontrol3......usercontrol10. I want to add
I have a UserControl with a Border element within it that I want to
I have a WPF UserControl with binding converters referenced like this: <UserControl x:Class=MyControl x:Name=MyControl
So I want to have multiple tabs with a usercontrol in it, depending on
I have a custom UserControl with an image and a label, both of which
In other words, I have a UserControl that has, for example, a label on
I have a simple UserControl containing Label, ComboBox and Button. In brief, it is
I have a custom UserControl (a label and a textbox). My problem is I
I have UserControl 'A' with a label, and this property: /// <summary> /// Gets
I have a WPF UserControl, which is simply a Label for whatever else it

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.