0

hi im again,,,,,,
thanx for daniweb i get the solution to my 1st problum.
now the second problum;

i have a textbox on my windows form and i need to validate it.
rule is user must not able to press any A-Z && a-z && !-* keys on the key bord.
if he is tring to pres any that kind of key the system must genarate a mesage box.
MessageBox.Show("bla bla bla"); :)

only the keys the user can pres on that text box must be 1,2,3,4....0.

i hop you guys will help me on this little thing.

:icon_wink:

thanxxxxx

5
Contributors
11
Replies
12
Views
7 Years
Discussion Span
Last Post by Ramy Mahrous
Featured Replies
  • 1
    sknake 1,622   7 Years Ago

    You might also consider using an [icode]ErrorProvider[/icode] instead of a message box. I hate it when applications pop up a dialog while typing. You could set the error message on an invalid key press and wait until the control loses focus or a valid key is pressed then clear the … Read More

  • 1
    ddanbe 2,577   7 Years Ago

    @Scott : I hate it when applications pop up a dialog while typing. I could not agree more:) ErrorProvider is a great way to go, but only if you have a few textboxes on your form. It tends to be buggy. : look at this [url=http://www.codeproject.com/KB/dotnet/ErrorProvider_ToolTipFix.aspx]example [/url] Read More

0

Try the following code in the textbox_Keypress Event!

if(((e.KeyChar < '0' || e.KeyChar >'9'))&&(e.KeyChar!='\b'))
        {
        MessageBox.Show("Please Enter Numbers only");
            e.Handled = true;
        }
        else
        {
        e.Handled=false;
        }

The above coding will enable the user to enter values from 0 -9 and will allow the user to erase the characters back(BackSpace).

Hope this helps you!

Edited by mike_2000_17: Fixed formatting

0

My solution Danny is more scalable
Don't depends on current requirements and you should have some flexibility
I argue using RegularExpression
pattern = .....
Then if this text matches the pattern return true to accept the value otherwise false.
I'll do code snippet for it soon.

1

You might also consider using an ErrorProvider instead of a message box. I hate it when applications pop up a dialog while typing. You could set the error message on an invalid key press and wait until the control loses focus or a valid key is pressed then clear the error.

Votes + Comments
Nice said!
1

@Scott : I hate it when applications pop up a dialog while typing.
I could not agree more:)
ErrorProvider is a great way to go, but only if you have a few textboxes on your form. It tends to be buggy. : look at this example

Votes + Comments
good information
0

@Scott : I hate it when applications pop up a dialog while typing.
I could not agree more:)
ErrorProvider is a great way to go, but only if you have a few textboxes on your form. It tends to be buggy. : look at this example

Ah, I did not realize that. I use DeveloperExpress controls where those had been fixed already -- plus they added a nice property .HasErrors which the stock error provider doesn't have or I haven't been able to find.

I use XtraForm, XtraButton, XtraPanel, XtraEverything. Developer express has awesome controls.

0

Developer Express seems a nice thing to have. I am reading more about it on their site. HasErrors may be simulated with GetError I guess. Look at the code example on this MSDN page

0

You're most welcome, Danny :)
I hope you like it, when I had facebook account I had 700 pics there, I may schedule changing my avatar periodically :D

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.