Good morning all. I think we are in for a rough ride those of us in the IT field. I feel fortunate to be employed and in a situation that is stable. I pray for all of you who are struggling right now.
So our topic today is how to handle events across multiple user controls. I have never been fond of custom controls simply because 9 times out of 10 it can be done with a out of the box control that is well documented and supported. But there are times when we have to use or support them so it is worthwhile to discuss. Make it a great day!
Public Class ucMain
Public Event MainFired(ByVal button As Integer)
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Simple sub control, containing a textbox.
Public Class ucSub
Public WithEvents maincontrol As ucMain
Public myNumber As Integer
Private Sub maincontrol_MainFired(ByVal button As Integer) Handles maincontrol.MainFired
If button = myNumber Then
TextBox1.Text = "Main fired"
Loading of subcontrol onto form using this code (in loop on i to give three instances for my test)
Dim c As New ucSub
c.myNumber = i
c.maincontrol = UcMain1
c.Top = 40 * i
c.Left = 200