Problems extending a control

jello

Member
Joined
Mar 12, 2008
Messages
11
Programming Experience
Beginner
I am attempting to practically do an example laid out in my textbook which is related to extending a control.

I have made a new Windows Application Project and written the following:
Public Class numerictextbox
Inherits System.Windows.Forms.TextBox

Protected Overrides Sub onkeypress(ByVal e As System.Windows.Forms.KeyPressEventArgs)

End Sub

Dim myn As New numerictextbox
myn.clear

End Class

However the "myn.Clear" function is giving me a syntax error: Declaration expected.

I would like to know:

1. What type of project should I make if I want to extend a control?

2. Where should my code be written so that there will not be problems like the one I am currently facing?
 
First up, you're getting that error message because you can't put anything but declarations outside of a method. If you want to call Clear on a NumericTextBox then you need to do so INSIDE a method.

Secondly, why would you create a NumericTextBox inside the NumericTextBox class? You'd only create one on a form, wouldn't you? I think you've misinterpreted something that your book has told you. The class and the overridden method would be correct. The other bits would not be part of that class but would be in a form somewhere.
 
Back
Top