Dll file contains form class and load event

kaveh rahimi 61 Reputation points

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
        pluggedInQuery = New WqlEventQuery
        pluggedInQuery.QueryString = "SELECT * FROM Win32_VolumeChangeEvent WHERE EventType = 2"
        pluggedInWatcher = New ManagementEventWatcher(pluggedInQuery)

        pluggedOutQuery = New WqlEventQuery
        pluggedOutQuery.QueryString = "SELECT * FROM Win32_VolumeChangeEvent WHERE EventType = 3"
        pluggedOutWatcher = New ManagementEventWatcher(pluggedOutQuery)
    Catch ex As Exception
    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.

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

Accepted answer
  1. Duane Arnold 3,221 Reputation points

    @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.


    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