[Gtk-sharp-list] Gtk entry only for digits?

Michael 26031@t-link.de
Sun, 29 Aug 2004 19:31:54 +0200


Jop, helped a lot :-)

I did it that way:

void InsertText(object o, TextInsertedArgs args)
        {                
                if(args.Text.Equals("1") || args.Text.Equals("2") 
                        || args.Text.Equals("3")
||                     args.Text.Equals("4") ||
                        args.Text.Equals("5") ||args.Text.Equals("6")
                        ||args.Text.Equals("7") ||args.Text.Equals("8")
                        ||args.Text.Equals("9") ||args.Text.Equals("0"))
                {
                        Console.WriteLine("Number pressed "+ args.Text);
                }
                else
                {                       
                        if(entry1.CursorPosition.Equals(0))
                        {
                                entry1.DeleteText(entry1.CursorPosition-2,entry1.CursorPosition-1);
                                Console.WriteLine("Text0: "+ args.Text);
                        }
                        else
                        {
                                entry1.DeleteText(entry1.CursorPosition,entry1.CursorPosition+1);
                                Console.WriteLine("Text1: "+ args.Text);
                        }
                }
        }

@ Draek: With KeyPressEventArgs you do not get any output in the console
if a digit is pressed. Only 'special keys' show an output.

Thanks a lot @ all

Michael


On Sun, 2004-08-29 at 12:51, Philipp Kern wrote:
> On So, 2004-08-29 at 09:41, Draek wrote:
> > I'm sure that you can do it with KeyPressEventArgs. What I would do
if I
> > was you is print the key code that is received to the console when
you
> > press numbers you will see what the key code is, just do a switch
> > statement on that keycode as a string and your set, only print the
> > numbers not letters.
> 
> Although I really do not know how to reach an Entry field without
alpha
> characters, this hardware method doesn't seem very natural to me.
> You get the hardware keycodes, so for providing proper editing
features
> you would also have to check the keypad (and if numlock is really on)
> etc.
> 
> Perhaps you might want to play with "insert_text" and int
> System.Int32.Parse(string).
> 
> Hope to help you just a little bit,
> Philipp Kern