目标:通过单击按钮,通过事件调用在文本框中获取价值。
问题:button1_click具有与我的自定义事件不同的签名,因此我无法从我的自定义事件中恢复值。
尝试:我尝试了项目控制台及其工作,但未尝试使用按钮。
这里是Windows窗体IHM的代码(可能是我需要做的事情:]:>
static void Main() { var pub = new InfosJoulemetre; var sub = new Form1("sub",pub); double value = 0.003; byte[] donnees = {0x60,0x0D}; pub.Event1(value,donnees): //some lines for launch form } private void button1_Click(object sender, EventArgs e) { //i want to call object from CatchEvent here, why not by the method CustomEvent i stated below but how?} public Form1(object sender, InfosJoulemetre e) { InfosJoulemetre pub = new InfosJoulemetre(); //from dll pub.NouvelleDonnees += CustomEvent; } void CustomEvent(objext sender, CatchEvent e) { textBox1.text = e.data.Tostring(); //doesnt work }
来自DLL的代码:
public delegate void EventHandler(object sender,CatchEvent e); public event EventHandler<CatchEvent> NouvelleDonnees; public void Event1(//some parameters in enter) { //some calculs resultat = //double value OnRaiseCustomEvent(new CatchEvent(resultat)); } public virtual void OnRaiseCustomEvent(CatchEvent e) { EventHandler<CatchEvent> raiseEvent = NouvelleDonnees; if(raiseEvent != null) raiseEvent(this,e); }
这里是代码类CatchEvent:
public class CatchEvent : EventArgs { public double data=0; public CatchEvent(double NouvelleDonnees) { data =NouvelleDonnees; } public double EventEnergy { get {return this.data;} } }
谢谢您的帮助!
目标:通过单击按钮,通过事件调用在文本框中获取价值。问题:button1_click具有与自定义事件不同的签名,因此我无法从自定义事件中恢复值。试试:我...
编辑:通过对您的@MarcGravell行的修改,我做到了: