vb.netdatetimetimer

Event load can't be found BC30590


I comeback with an error BC30590 the event Load can't be flound. I want to display date and time on a mMain form This is the code but is not working. Thank you very much.

Public Class MainForm

    Private WithEvents myTimer As New Timer()
    Private Label1 As Object
    Dim WithEvents Load As New EventArgs

    Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Start the Timer when the form loads
        myTimer.Interval = 1000 ' 1 second
        myTimer.Start()
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles myTimer.Tick
        ' Update the label with the current date and time
        Label1.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
    End Sub
End Class

I would like to display in a label the current date and time on the Main form, I using a label1 and timer.


Solution

  • Is that class even a form? Can you open it in the designer? If not, get rid of it altogether and actually add a form to your project, which you can do from the Project menu or by right-clicking the project in the Solution Explorer.

    Assuming the class is a form, get rid of this line:

    Dim WithEvents Load As New EventArgs
    

    as that makes no sense at all. You should also get rid of this line:

    Private Label1 As Object
    

    and actually add a Label to the form in the designer. You should probably get rid of this line too:

    Private WithEvents myTimer As New Timer()
    

    and add the Timer in the designer too, although you can create it in code if you want to.