Solved

Enabling keypress KeyChar

Posted on 2009-05-19
1
286 Views
Last Modified: 2012-06-21
Hi,
I want to enable "-" inside the if statement what should i add to include it?
Is there a list of Chars i can refer to incase i want to add in other characters in the future.

Thanks for the help in advcance
if (!char.IsLetterOrDigit(e.KeyChar) && e.KeyChar != '\b')
            {
                e.Handled = true;
            }

Open in new window

0
Comment
Question by:csharp_learner
1 Comment
 
LVL 3

Accepted Solution

by:
SafeCode earned 350 total points
ID: 24420196
Hi,
to make if statement true for symbols but backspace or minus, add e.KeyChar != '-'

list of escape sequences can be found here:
http://blogs.msdn.com/csharpfaq/archive/2004/03/12/88415.aspx

Hope this helps!
if (!char.IsLetterOrDigit(e.KeyChar) && e.KeyChar != '\b' && e.KeyChar != '-')
            {
                e.Handled = true;
            }

Open in new window

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Device Location 4 35
Finally almost got it 5 48
Where did System.Data.Objects go? 2 40
custom authorization on controller action and HTML in asp.net mvc 1 25
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question