|
-
Dec 19th, 2007, 02:38 PM
#1
Thread Starter
Junior Member
Textbox AlphaNumeric with windows special keys?
Hi all,
I was looking for a textbox that can hold alphanumerics only and one can also use windows shortcuts such as control+v Control+c Control+a within that textbox.
I tried this in my keypress event for the text box and it works, but i would like for it to also allow the other windows shortcut functions
6 Code:
if (!(Char.IsLetterOrDigit(e.KeyChar) == true || (e.KeyChar) == 8))
{
e.Handled = true;
}
Take care
P.s. I would like to not use the masked text box.
-
Dec 19th, 2007, 07:30 PM
#2
Re: Textbox AlphaNumeric with windows special keys?
Use the Char.IsControl method to test for control characters.
-
Dec 19th, 2007, 10:12 PM
#3
Thread Starter
Junior Member
Re: Textbox AlphaNumeric with windows special keys?
Thanks jmc
This is what i have so far and it seems to work.
Code:
protected override void OnKeyPress(KeyPressEventArgs e)
{
if ((Char.IsControl(e.KeyChar) == true))
{
e.Handled = false;
}
else if (!(Char.IsLetterOrDigit(e.KeyChar) == true || (e.KeyChar) == 8))
{
e.Handled = true;
}
}
Is there anyway i can check to validate something that is pasted into a textbox as well? i.e. if someone pastes axx@!!#333321 it shouldnt let them paste it into the textbox.
-
Dec 19th, 2007, 11:52 PM
#4
Re: Textbox AlphaNumeric with windows special keys?
There's not really a simple way to do that. You could test for the Ctrl+V character or key combination and then validate the contents of the clipboard. That doesn't stop the user right-clicking the control and selecting Paste from the standard menu though. If you've overridden the standard menu then that's OK, but otherwise you would have to override the WndProc method and get your hands a bit dirtier.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|