Event needs WithEvents?

Connor Frayne 20 Reputation points
2024-08-01T17:51:55.6866667+00:00

Hello,

I have this in Form1,

Public Event BTN_PROF_Details_Event()
Private Sub FID_Container_Click(sender As Object, e As EventArgs) Handles BTN_PROF_Details.Click
    RaiseEvent BTN_PROF_Details_Event()
End Sub

Then this is in an Object class

Private Sub PNL_PROF_FID_Event(ByVal sender As Object, ByVal e As EventArgs) Handles BTN_PROF_Details_Event
        Trace.WriteLine("test")
End Sub

My problem stems from the event requiring WithEvents?

User's image

How could I fix this?

Thank you,

Connor Frayne

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,668 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,680 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 115.2K Reputation points
    2024-08-01T19:40:22.8466667+00:00

    This should work in your class:

    Public WithEvents f1 As Form1
    
    Private Sub PNL_PROF_FID_Event() Handles f1.BTN_PROF_Details_Event
       Trace.WriteLine("test")
    End Sub
    

    The Form1 form must be assigned to f1. (You can use Me if the object is created inside the Form1).

    0 comments No comments