[Gtk-sharp-list] GtkEntry input validation

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

[Gtk-sharp-list] GtkEntry input validation

by Jesper K. Pedersen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Being completely new with Gtk# I have been trying to write a small
"getting started" application.
It is just a small calculator to learn about the various gui controls
and just getting into the C# programming language.

I have run into a difficulty of limiting the input of the entry/result
display to only allow for certain characters (currently I only do math
with the common "10" digit system + ".")

I did take a peek at the Gtk+ FAQ showing an example in C + Gtk about
validating input (section 6.15 "How do I validate/limit/filter the
input to a GtkEntry? [GTK 2.x]").

Do anyone have any similar piece of code for the Gtk# ?

What I in essense is trying is to read off any keypress events in my
window and if they are a digit/dot enter them into the calculator
display (of type GtkEntry)

One of my problems is that just setting the GtkEntry editable to false
still doesnt let my keypress event handler get the event for things
like <backspace> <del> and so on (I suspect they are "eaten" by the
GtkEntry)

Any ideas is greatly appreciated to this "newbie" programmer in C#/Gtk#

Best regards
Jesper K. Pedersen
_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@...
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Re: [Gtk-sharp-list] GtkEntry input validation

by Jacob Ilsø Christensen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi.

On 12/9/06, Jesper K. Pedersen <jkp@...> wrote:

> Being completely new with Gtk# I have been trying to write a small
> "getting started" application.
> It is just a small calculator to learn about the various gui controls
> and just getting into the C# programming language.
>
> I have run into a difficulty of limiting the input of the entry/result
> display to only allow for certain characters (currently I only do math
> with the common "10" digit system + ".")
>
> I did take a peek at the Gtk+ FAQ showing an example in C + Gtk about
> validating input (section 6.15 "How do I validate/limit/filter the
> input to a GtkEntry? [GTK 2.x]").
>
> Do anyone have any similar piece of code for the Gtk# ?

This works for me:

http://lists.ximian.com/pipermail/gtk-sharp-list/2004-November/005148.html

I don't know if there is a better way...

/Jacob

>
> What I in essense is trying is to read off any keypress events in my
> window and if they are a digit/dot enter them into the calculator
> display (of type GtkEntry)
>
> One of my problems is that just setting the GtkEntry editable to false
> still doesnt let my keypress event handler get the event for things
> like <backspace> <del> and so on (I suspect they are "eaten" by the
> GtkEntry)
>
> Any ideas is greatly appreciated to this "newbie" programmer in C#/Gtk#
>
> Best regards
> Jesper K. Pedersen
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list@...
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
>
_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@...
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Re: [Gtk-sharp-list] GtkEntry input validation

by acen28 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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
}


Jacob Ilsø Christensen wrote:
Hi.

On 12/9/06, Jesper K. Pedersen <jkp@solnet.homeip.net> wrote:
> Being completely new with Gtk# I have been trying to write a small
> "getting started" application.
> It is just a small calculator to learn about the various gui controls
> and just getting into the C# programming language.
>
> I have run into a difficulty of limiting the input of the entry/result
> display to only allow for certain characters (currently I only do math
> with the common "10" digit system + ".")
>
> I did take a peek at the Gtk+ FAQ showing an example in C + Gtk about
> validating input (section 6.15 "How do I validate/limit/filter the
> input to a GtkEntry? [GTK 2.x]").
>
> Do anyone have any similar piece of code for the Gtk# ?

This works for me:

http://lists.ximian.com/pipermail/gtk-sharp-list/2004-November/005148.html

I don't know if there is a better way...

/Jacob

>
> What I in essense is trying is to read off any keypress events in my
> window and if they are a digit/dot enter them into the calculator
> display (of type GtkEntry)
>
> One of my problems is that just setting the GtkEntry editable to false
> still doesnt let my keypress event handler get the event for things
> like <backspace> <del> and so on (I suspect they are "eaten" by the
> GtkEntry)
>
> Any ideas is greatly appreciated to this "newbie" programmer in C#/Gtk#
>
> Best regards
> Jesper K. Pedersen
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
>
_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list