[英]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"); 但是它将运行,因为当我调用该函数时,它是: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'? 我要问的是如何使用“名称”之类的“自定义”参数,并仍然传递“发件人”和“参数”的值?
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.