Baderous Posted May 24, 2008 at 08:43 PM Report Share #187255 Posted May 24, 2008 at 08:43 PM O que eu quero é fazer com que uma textbox só permita escrever números, isto é, se o utilizador escrever um caracter alfabético na textbox este não é inserido, não aparece. Só aparece alguma coisa se essa coisa for um número. Como faço isso? Link to comment Share on other sites More sharing options...
DanielAmorim Posted May 24, 2008 at 09:09 PM Report Share #187261 Posted May 24, 2008 at 09:09 PM Podes registar uma função num dos eventos de Key da textbox, KeyDown por exemplo. Depois vês qual foi a Key pressionada e se não for um numero afectas a propriedade SuppressKeyPress, KetEventArgs, com o valor true. Daniel Amorim VP for xRTML http://www.xrtml.org http://www.realtime.co Link to comment Share on other sites More sharing options...
Betovsky Posted May 24, 2008 at 11:16 PM Report Share #187280 Posted May 24, 2008 at 11:16 PM Podes também usar antes uma MaskedTextBox. Que é exactamente para esses casos que ela existe. "Give a man a fish and he will eat for a day; Teach a man to fish and he will eat for a lifetime. The moral? READ THE MANUAL !" Sign on a computer system consultant's desk Link to comment Share on other sites More sharing options...
Guest id194 Posted May 25, 2008 at 12:21 AM Report Share #187294 Posted May 25, 2008 at 12:21 AM Podes também usar antes uma MaskedTextBox. Que é exactamente para esses casos que ela existe. Era o que eu ia sugerir... 😄 Link to comment Share on other sites More sharing options...
grabitzz Posted May 26, 2008 at 10:00 AM Report Share #187516 Posted May 26, 2008 at 10:00 AM No evento KeyPress basta pôr este código que faz exactamente o que necessitas. private void Textbox_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsNumber(e.KeyChar) && !char.IsControl(e.KeyChar)) { e.Handled = true; } } Link to comment Share on other sites More sharing options...
kombypetras Posted July 13, 2009 at 07:51 PM Report Share #279232 Posted July 13, 2009 at 07:51 PM Boas pessoal. Como posso fazer para que só sejam adicionados números numa textBox numa aplicação WPF. É que não me deixa utilizar uma MaskedTextBox e não estou a conseguir definir alguns métodos que tenho encontrado aqui pela net. Cumps. Link to comment Share on other sites More sharing options...
renafi Posted July 13, 2009 at 08:32 PM Report Share #279249 Posted July 13, 2009 at 08:32 PM Crias uma regular expression: http://www.regular-expressions.info/ Oracle Certified Professional - AdministraçãoOracle Certified Professional - Pl/sqlMCPD - Microsoft Certified Professional DeveloperMCTS - Microsoft Certified Technology Specialist Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now