Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Numeric text box like VFP
Message
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
00754811
Message ID:
00754844
Vues:
22
It is best to subclass the textbox and add the functionality. You need to trap the key strokes. Here is how to do it from the site http://www.syncfusion.com/faq/winforms/search/830.asp:
[C#] 
public class NumbersOnlyTextBox : TextBox 
{ 
     public NumbersOnlyTextBox() 
     { 
          this.KeyPress += new KeyPressEventHandler(HandleKeyPress); 
     } 
 
     private void HandleKeyPress(object sender, KeyPressEventArgs e) 
     { 
          if(!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar)) 
               e.Handled = true; 
     } 
} 
 
[VB.NET] 
Public Class NumbersOnlyTextBox 
     Inherits TextBox 
 
     Public Sub New() 
          AddHandler Me.KeyPress, AddressOf HandleKeyPress 
     End Sub 'New 
 
     Private Sub HandleKeyPress(sender As Object, e As KeyPressEventArgs) 
          If Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) Then 
              e.Handled = True 
          End If 
     End Sub 'HandleKeyPress 
End Class 'NumbersOnlyTextBox
>Hi Guys,
>Is there any control or code which I can use to have a numeric text box like VFP. Only numerics.
>TIA
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform