https://github.com/fabioingenito/csharp_somentenumero
if (!(e.KeyChar >= '0' && e.KeyChar <= '9') && e.KeyChar != 8) e.Handled = true;
https://github.com/fabioingenito/csharp_somentenumero
csharp vitrinedev
Last synced: 9 months ago
JSON representation
if (!(e.KeyChar >= '0' && e.KeyChar <= '9') && e.KeyChar != 8) e.Handled = true;
- Host: GitHub
- URL: https://github.com/fabioingenito/csharp_somentenumero
- Owner: FabioIngenito
- Created: 2017-02-28T18:25:34.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-11-30T16:57:21.000Z (over 3 years ago)
- Last Synced: 2025-07-02T14:50:43.243Z (about 1 year ago)
- Topics: csharp, vitrinedev
- Language: C#
- Homepage:
- Size: 14.6 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
SOMENTE NÚMEROS
| :placard: Vitrine.Dev | |
| ------------- | --- |
| :sparkles: Nome | **CSharp_SomenteNumero**
| :label: Tecnologias | VB6 VB.Net C#
Detalhes do projeto
Restringir a "TextBox" para receber SOMENTE NÚMEROS com somente uma linha de código:
if (!(e.KeyChar >= '0' && e.KeyChar <= '9') && e.KeyChar != 8) e.Handled = true;
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
//Escreve-se em VB 6 assim:
//Written in VB 6 as follows:
//If InStr("0123456789", Chr(KeyAscii)) = 0 nd KeyAscii <> 8 Then KeyAscii = 0
//Migrado para VB.NET:
//Migrated to VB.NET:
//If InStr("0123456789", e.KeyChar) = 0 And Not Convert.ToInt32(e.KeyChar) = Keys.Back Then e.Handled = True
//Melhorada a Migração:
//Improved the migration:
//If Not Char.IsNumber(e.KeyChar) And Not Convert.ToInt32(e.KeyChar) = Keys.Back Then e.Handled = True
//E C#
//And C#
if (!(e.KeyChar >= '0' && e.KeyChar <= '9') && e.KeyChar != 8) e.Handled = true;
End Sub