Making label on UserControl work as default click event
-
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
-
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
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 -
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
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 -
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 ClassThat's what I meant, and that's what I need! Thanks you very much, this does the trick :)
-
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 KreskowiakYes the label taking up the entire surface was the issue, solved with Me.OnClick(EventArgs.Empty). Thank you for your reply sir :)