An open API service indexing awesome lists of open source software.

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;

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