JimA
New member
I created a simple class to add a little functionality to a button control:
Public Class pwButton
Inherits System.Windows.Forms.Button
Public Sub New()
MyBase.New()
ForeColor = Color.Indigo
BackColor = Color.LightGray
Height = 10
End Sub
End Class
After building, the control can be added to the controls box and placed on a form. However, this line of code...
Private Sub btn_Click(sender As System.Object, e As System.EventArgs) Handles PwButton1.Click
results in the error...
Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
After much searching and reading, I discovered that the declaration line in the forms designer failed to add a Withevents keyword. Changing this line...
Friend PwButton1 As Controls.Controls.pwButton
to...
Friend WithEvents PwButton1 As Controls.Controls.pwButton
solved the issue. That's good, and I learned a lot in tracking down what's going on, but I'd prefer that the WithEvents keyword was added when placing the control on the form as it does with the regular .net controls. Not a big deal, but I'm curious about why it's missing.
Suggestions on what I might have missed?
Thanks,
Jim
Public Class pwButton
Inherits System.Windows.Forms.Button
Public Sub New()
MyBase.New()
ForeColor = Color.Indigo
BackColor = Color.LightGray
Height = 10
End Sub
End Class
After building, the control can be added to the controls box and placed on a form. However, this line of code...
Private Sub btn_Click(sender As System.Object, e As System.EventArgs) Handles PwButton1.Click
results in the error...
Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
After much searching and reading, I discovered that the declaration line in the forms designer failed to add a Withevents keyword. Changing this line...
Friend PwButton1 As Controls.Controls.pwButton
to...
Friend WithEvents PwButton1 As Controls.Controls.pwButton
solved the issue. That's good, and I learned a lot in tracking down what's going on, but I'd prefer that the WithEvents keyword was added when placing the control on the form as it does with the regular .net controls. Not a big deal, but I'm curious about why it's missing.
Suggestions on what I might have missed?
Thanks,
Jim