[学习日记]对控件的继承和重载

今天在学习有关CLASS的继承后,有后领悟
就写了一个CLASS来继承textbox,嘿嘿,成功了!
当然还对其进行了重载,对输入的字符类型进行了限制,使其只能输入数字。
继承类如下:
Public Class NumericTextBox 
Inherits System.Windows.Forms.TextBox
Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs) 
e.Handled 
= Not Char.IsDigit(e.KeyChar) 
End Sub
 
End Class
 

在窗外中调用此类代码如下:

#Region " Windows 窗体设计器生成的代码 "
'
 Friend WithEvents TextBox1 As NumericTextBox

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.TextBox1 
= New NumericTextBox
 Me.SuspendLayout()
        
'
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(2424)
        Me.TextBox1.Name 
= "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(15221)
        Me.TextBox1.TabIndex 
= 0
        Me.TextBox1.Text 
= "123"
        '
'
.
   End Sub


#
End Region

其效果如图:
form1.JPG

嘿嘿!主要功能当然是都完成了,也成功了,可是遇到一个问题,因为限制只能输入数字,结果按小数点、减号和后退BCAK SPACE键都不起作用,就不能输入小数、负数和修改数值了,麻烦。
请高手帮忙修改一下,让其能输入现实意义的数字,并能修改。
posted @ 2005-03-11 10:39  Aowind  阅读(1419)  评论(2编辑  收藏  举报