C# - dll event handler -
i setting .dll file create new form , new button, want button something. possible create event handler in dll file?
public static byte sbuton( string er, int by,int re) { form fg = new form(); fg.show(); button b1 = new button(); fg.controls.add(b1); b1.text = er; b1.location = new point(by, re); return 0; }
this code creates form button in it. when try create new event handler, in form, error: "an object reference required non-static field, method or property".
public static byte sbuton( string er, int by,int re) { form fg = new form(); fg.show(); button b1 = new button(); fg.controls.add(b1); b1.text = er; b1.location = new point(by, re); b1.click += new eventhandler(b1_click); } private void b1_click(object sender , eventargs e) { }
code form want use dll private void button1_click(object sender, eventargs e) { if (richtextbox1.text.contains("add") && richtextbox1.text.contains("buton") && richtextbox1.text.contains("text")) { form.sbuton("buton", 10, 10); } }
creates button, nothing happens when button clicked, because no event handler assigned in .dll file. , also,sorry bad english,it not native language. what can do? thanks!
it's not clear question context is. without a good, minimal, complete code example it's difficult provide answer.
but in example, appears event handler in same dll (and assume, same class) sbuton()
method. if that's case, need in order use event handler make static
method:
private static void b1_click(object sender , eventargs e) { }
now, since didn't post of code in method, never mind full context, it's not work. i.e. if there reason method being non-static method, have subscribe event handler referring method reference actual instance of containing class. if that's case, question commenter daniel kelley suggests, an object reference required non-static field, method, or property?, may turn out appropriate needs after all.
finally, note none of has code being in dll. have run same problem had sbuton()
method been in same project you're calling it.
Comments
Post a Comment