-
Hi all,
I am working on an app which will display custom controls (just a picbox and label) i created in a tablelayoutpanel.
because I am adding controls programatically I need to assign it a click method. I know how to do that but the problem is that it only fires if the control (not the actual picture box or label) is clicked if I click on a picture box on control it doesn't fire. I thought that if I create a custom control that on outside it acts as one homogene control.
Private Sub DeviceData_Click(ByVal sender As Object, ByVal e As System.EventArgs)
System.Windows.Forms.MessageBox.Show("test")
End Sub
AddHandler _DeviceData.Click, AddressOf DeviceData_Click
Thanks for any help.
Regards,
Greg
-
Try to disable picture box. But if this will not help properly, you must handle internal controls and in handle routines you simply RaiseEvent Me.Click ... for doing that programatically you can For Each ctrl in Me.controls ... in sub new
-
so you cannot fire directly your usercontrol's click event. in this case you must create e.g. BuchClick event for your UserControl, and bring all clickEvents (also UserControl's) together in one handler, which rises your BunchClick... Tip: you can still recognize source object if your BunchClick preserves classical click handler interface (object,eventArgs).
-
I don't quite understand what you ment with the rest of suggestions, but disabling picture box helped!!! :) thanks a lot
-
the rest is quite more valid solution than disabling :)
I will try to show it via pseudocode
Class myUserCtrl
{
withevents myPictureBox, myLabel
public event BunchClick(sender, e as eventArgs)
Sub myPictureBox_Click(sender, e) Handles myPictureBox.Click
{
raiseevent BunchClick(sender, e)
}
Sub myLabel_Click -- the same handler as mypicturebox
Sub myUserControl_Click -- the same
}
Class myFormWithUserControl
{
Sub myUserControl_BunchClick(sender, e) Handles myUserControl.BunchClick
...
}
Or as I told, you can bypass creating of each handler for userControl's children controls, when creating only MyUserControl_Click handler and in sub new of userControl, you can use
For each ctrl as control in Me.Controls
addHandler ctrl.click, AddressOf me.MyUserControl_Click
raisning BunchClick from this universal handler stays the same as in pseudocode...
-
ah, it replaced underScore with bunch of LineFeeds :)
-
Thanks, I forgot to post an reply earlier but I figured it out after all (using your suggestion in first post)
Thanks again for effort
Greg
Enter your message below
Sign in or Join us (it's free).