Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Inputmask for Textbox
Message
From
15/11/2012 06:24:38
 
 
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01557193
Message ID:
01557257
Views:
41
>>Hi,
>>
>>I have a textbox that I want to limit a user to only entering two characters (could be any characters, numbers or anything on the keyboard). I would love to force them to upper case if they are letters and only allow two characters.
>>
>>The VFP equivalent of inputmask = "!!"
>>
>>Any ideas?
>
>Set Textbox.Max.Length =2, TextBox.CharacterCasing = CharacterCasing.Upper
>then:
protected override void OnPreviewTextInput(System.Windows.Input.TextCompositionEventArgs e)
>       {
>         char c = e.Text.ToCharArray()[0];
>         if (Char.IsControl(c) || Char.IsLetterOrDigit(c))
>         base.OnPreviewTextInput(e);
>         else
>         {
>           e.Handled = true;
>         }
>       }
>
>Update: Just noticed you don't actually care what the characters are so the override isn't neccessary. Still it may give you an idea of how this approach could be expanded in future :-}

Thanks Viv, I was going to ask why the code was necessary, but at least it is a good example of what I can do in the future.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Reply
Map
View

Click here to load this message in the networking platform