I keep getting an error saying method 'btnLogin_click' cannot handle event Click
because they do not have a compatible signature.
If anyone has some insight as to why its doing this, please enlighten me.
Public Sub btnLogin_Click(sender As Object, e As EventArgs, messageBox As MessageBox) Handles btnLogin.Click
Dim strUser As String = txtUser.Text
Dim strpass As String = txtPass.Text
If (strUser = "drake" And strpass = ("1")) Then
MessageBox.Show("This is where we take the user to the bard lounge.")
ElseIf Not (strUser = "drake" And strpass = ("1")) Then
txtPass.Text = ("") And MessageBox.Show("Incorrect username and/or password.")
End If
End Sub
This was supposed to be a simple login screen to open a windows form if you use the right username and password. I made this by following a tutorial for a login screen from youtube, and then optimizing the code as much as possible, with some help from my uncle who is a coding veteran of 20 years.
Once I got it cleaned up, I started working on my own features. I tried to make the txtPass
text box clear itself if the pass/user were incorrect upon clicking the login button btnLogin
. But as soon as I try to run the program it gives me an error that didn't show up in the development tab before. I already attempted to use Clear()
rather than txtPass.text = ""
however it only gave me more errors I couldn't understand.
CodePudding user response:
It's not the Button
that is the problem but your code. When an event is raised, the object raising the event calls the method registered as the event handler. You can't just put whatever parameters you want in that method. In your case, how is the Button
supposed to pass an argument for that third parameter when the person who wrote the code for the Button
class years ago had no idea that parameter would exist? You're not even using that parameter inside the method anyway, so what is it for? Just change the method declaration to what it should have been in the first place and it will work:
Public Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
That's what would have been generated in the first place if you had just double-clicked the Button
in the designer. You can't arbitrarily add parameters to an event handler. The object raising the event expects a specific signature so your method has to have that signature.