Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Inputmask for Textbox
Message
De
15/11/2012 06:24:38
 
 
À
15/11/2012 04:19:46
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Divers
Thread ID:
01557193
Message ID:
01557257
Vues:
40
>>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform