Allowing only digit input to any entry: Sample

View: New views
1 Messages — Rating Filter:   Alert me  

Allowing only digit input to any entry: Sample

by acen28 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I was trying to allow only digits in entrytext. Althought there are many sample sources on this issue for MSDotnet, for GtkSharp samples are poor. Finally I have succesfully completed my code. I hope it will be useful for coders.

protected virtual void OnEntry1TextInserted (object o, Gtk.TextInsertedArgs args)
{
if(Char.IsDigit(Convert.ToChar(args.Text))==false && Convert.ToChar(args.Text) !=',' && !char.IsControl(Convert.ToChar(args.Text)))
{
entry1.DeleteText(entry1.Text.Length-1, entry1.Text.Length);
}
//you may add a messagebox here to warn users for typing only digits
}