Dll file contains form class and load event

kaveh rahimi 61 Reputation points
2021-05-09T08:30:51.463+00:00

Hi ,my code is:
Imports System.Management
Imports System.Windows.Forms
Imports System.Runtime

Public Class Form1
Dim WithEvents pluggedInWatcher As ManagementEventWatcher
Dim WithEvents pluggedOutWatcher As ManagementEventWatcher
Dim pluggedInQuery As WqlEventQuery
Dim pluggedOutQuery As WqlEventQuery

Private Sub Form1_load(sender As Object, e As EventArgs) Handles MyBase.load
    Try
        pluggedInQuery = New WqlEventQuery
        pluggedInQuery.QueryString = "SELECT * FROM Win32_VolumeChangeEvent WHERE EventType = 2"
        pluggedInWatcher = New ManagementEventWatcher(pluggedInQuery)
        pluggedInWatcher.Start()

        pluggedOutQuery = New WqlEventQuery
        pluggedOutQuery.QueryString = "SELECT * FROM Win32_VolumeChangeEvent WHERE EventType = 3"
        pluggedOutWatcher = New ManagementEventWatcher(pluggedOutQuery)
        pluggedOutWatcher.Start()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Sub

Private Sub pluggedInWatcher_EventArrived(sender As Object, e As EventArrivedEventArgs) Handles pluggedInWatcher.EventArrived
    MessageBox.Show("Plugged In")
End Sub

Private Sub pluggedOutWatcher_EventArrived(sender As Object, e As EventArrivedEventArgs) Handles pluggedOutWatcher.EventArrived
    MessageBox.Show("Plugged Out")
End Sub

End Class
At compile time I receive: Event 'load' cannot be found error.
I guess that is because imports at the top of the code.
Please help.
Thanks

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

Accepted answer
  1. Duane Arnold 3,216 Reputation points
    2021-05-09T08:50:49.767+00:00

    @kaveh rahimi

    The name of Form1_Load is correct. The one you have in your code is wrong, and you don't have an event name 'load'.

    Example of the event for Form_Load is in the link.

    https://www.tutorialspoint.com/vb.net/vb.net_forms.htm

    If you want a valid Form_Load event place holder placed in the code, just double-click the form in the VS designer pane.

    0 comments No comments

0 additional answers

Sort by: Most helpful