Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Inheriting from existing windows control?

I'm trying to create a user control inherited from an existing control (textbox). 

I'm using an example from:

But it doesn't work.

If I try to create an Inherited User Control I get an error that there isn't an existing Assembly to work with.

If I create a new user control and then try to define that as inheriting from the Textbox (code below), I get syntax errors.

To create a new Inherited control you must specify a Windows Form control as a base class for this control. The following sample code creates a textbox that accepts only numbers as user input.To implement that functionality you must override the OnKeyPress method as shown below.


Public Class NumberOnlyBox Inherits System.Windows.Forms.TextBox

Protected Overrides Sub OnKeyPress(ByVal e as KeyPressEventArgs)
If Char.IsNumber(e.KeyChar)=False Then
End If
End Sub

End Class 

    Error    1        Syntax error.    C:\Documents and Settings\Clay Nichols\Local Settings\Application Data\Temporary Projects\WindowsControlLibrary1\UserControl1.vb    1    0            
    Error    2        End of statement expected.    C:\Documents and Settings\Clay Nichols\Local Settings\Application Data\Temporary Projects\WindowsControlLibrary1\UserControl1.vb    3    27            
    Error    3        sub 'OnKeyPress' cannot be declared 'Overrides' because it does not override a sub in a base class.    C:\Documents and Settings\Clay Nichols\Local Settings\Application Data\Temporary Projects\WindowsControlLibrary1\UserControl1.vb    5    28            

I'm using VS 2005 Beta.  Is this perhaps just a vs bug? I don't have VS 2003 installed, so I can't test vs. that.

Mr. Analogy {Shrinkwrap ISV Owner}
Saturday, January 8, 2005

Start by putting the Inherits statement on its own line.

Sunday, January 9, 2005

Thanks. That helps.

Mr. Analogy {ISV owner}
Tuesday, January 11, 2005

*  Recent Topics

*  Fog Creek Home