Estaba realizando un programa con una clase heredada de TextBox que solo permita números en el.
Con lo corto que es el código no haría falta ni una clase.
Me gustaría saber si voy por buen camino o debo mejorar este ejemplo: (mejorar para que funcione mejor,ya sabemos que todo es mejorable.. )
Este ejemplo esta hecho en Gambas3
En Fmain:
Private micajatexto As CajaTexto
Public Sub Form_Open()
Dim anchura As Integer = 150
Dim altura As Integer = 25
Dim x As Integer = 80
Dim y As Integer = 50
micajatexto = New CajaTexto(Me, anchura, altura, x, y) As "Hmicajatexto"
End
Public Sub hmicajatexto_Keypress()
micajatexto.teclapulsada(Key.Code)
End
Public Sub Form_Open()
Dim anchura As Integer = 150
Dim altura As Integer = 25
Dim x As Integer = 80
Dim y As Integer = 50
micajatexto = New CajaTexto(Me, anchura, altura, x, y) As "Hmicajatexto"
End
Public Sub hmicajatexto_Keypress()
micajatexto.teclapulsada(Key.Code)
End
La clase cajatexto
Inherits TextBox
Public Sub _new(ianch As Integer, ialt As Integer, ix As Integer, iy As Integer)
Me.Height = ialt
Me.Width = ianch
Me.x = ix
Me.y = iy
Me.Show()
End
Public Sub teclapulsada(tecla As Integer)
'Si las teclas pulsadas no son números para el evento
If Not (Key.Code >= Key["0"] And Key.Code <= Key[9]) Then Stop Event
End
Public Sub _new(ianch As Integer, ialt As Integer, ix As Integer, iy As Integer)
Me.Height = ialt
Me.Width = ianch
Me.x = ix
Me.y = iy
Me.Show()
End
Public Sub teclapulsada(tecla As Integer)
'Si las teclas pulsadas no son números para el evento
If Not (Key.Code >= Key["0"] And Key.Code <= Key[9]) Then Stop Event
End
Curiosidades: En Gambas2 si hago:
micajatexto = New CajaTexto(Me, anchura, altura, x, y) As "Hmicajatexto"
No hay posibilidad de que salga Me, solo las opciones de propiedades.
En Gambas2 al hacer un:
No se limitaría solo a minúscula si no que entraría también la mayúscula.
Podría haber puesto las propiedades de tamaño en la clase, pero serian fijas.
Saludos.