Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Making label on UserControl work as default click event

Making label on UserControl work as default click event

Scheduled Pinned Locked Moved Visual Basic
help
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Floodlight
    wrote on last edited by
    #1

    Hello, I have built a custom control where I use a label to effectively work as a button on this control. The problem is, when I place this control on my forms, I want the click event of that label to handle the click event of the user control. The label takes up the whole UserControl form. Hope this makes sense, and any help would be appreciated! Thanks

    T D 2 Replies Last reply
    0
    • F Floodlight

      Hello, I have built a custom control where I use a label to effectively work as a button on this control. The problem is, when I place this control on my forms, I want the click event of that label to handle the click event of the user control. The label takes up the whole UserControl form. Hope this makes sense, and any help would be appreciated! Thanks

      T Offline
      T Offline
      TnTinMn
      wrote on last edited by
      #2

      I really do not understand what you mean by " I want the click event of that label to handle the click event of the user control.". If you mean that you want to raise the usercontrol click event when the label is clicked, then this should do the trick.

      Public Class UserControl1
      Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
      OnClick(e)
      End Sub
      End Class

      F 1 Reply Last reply
      0
      • F Floodlight

        Hello, I have built a custom control where I use a label to effectively work as a button on this control. The problem is, when I place this control on my forms, I want the click event of that label to handle the click event of the user control. The label takes up the whole UserControl form. Hope this makes sense, and any help would be appreciated! Thanks

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        If the Label takes up the entire surface of the UserControl, the UserControl will never fire the Click event. The click will land on the Label since the mouse cannot "see" the UserControl surface through the label. Or is there something you're not describing in your post??

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        F 1 Reply Last reply
        0
        • T TnTinMn

          I really do not understand what you mean by " I want the click event of that label to handle the click event of the user control.". If you mean that you want to raise the usercontrol click event when the label is clicked, then this should do the trick.

          Public Class UserControl1
          Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
          OnClick(e)
          End Sub
          End Class

          F Offline
          F Offline
          Floodlight
          wrote on last edited by
          #4

          That's what I meant, and that's what I need! Thanks you very much, this does the trick :)

          1 Reply Last reply
          0
          • D Dave Kreskowiak

            If the Label takes up the entire surface of the UserControl, the UserControl will never fire the Click event. The click will land on the Label since the mouse cannot "see" the UserControl surface through the label. Or is there something you're not describing in your post??

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            F Offline
            F Offline
            Floodlight
            wrote on last edited by
            #5

            Yes the label taking up the entire surface was the issue, solved with Me.OnClick(EventArgs.Empty). Thank you for your reply sir :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups