jabbawabba
jabbawabba

Reputation: 69

Use 'custom' parameters in function, for entry widget (GTK#)

Is there a way that I am able to use 'custom' parameters with a function that is used when the value in an entry widget is changed.

the basic function is:

    public void(object sender, EventArgs args){
        Entry ent1 = (Entry)sender;
    }

what I tried:

    public void onChange(object sender, EventArgs args, String name){
        Entry ent1 = (Entry)sender;
    }

but It would run, because when I was calling the function it was: entry1 += onChange("testname");

which only passes one paramter to the function, when it needs three. What I'm asking is how can I use a 'custom' paramter like 'name', and still pass the values for 'sender' and 'args'?

Upvotes: 0

Views: 104

Answers (1)

Lasse V. Karlsen
Lasse V. Karlsen

Reputation: 391316

You will have to create a delegate that wraps code that passes that extra parameter.

You should be able to do it with this syntax:

entry1 += (s, e) => onChange(s, e, "testname");

However, this will make you unable to unsubscribe that event. If you need that, you will have to store the delegate:

ChangeEventHandler onchange = (s, e) => onChange(s, e, "testname");
entry1 += onchange;
...
entry1 -= onchange;

Upvotes: 1

Related Questions