c# - How to call back parameter? -
i want set textbox.text class1, when press button nothing happens. what's wrong?
namespace windowsformsapplication1 { public partial class form1 : form { public form1() { initializecomponent(); } class1 c; private void button1_click(object sender, eventargs e) { c = new class1(); c.x(); } } } and code class1
namespace windowsformsapplication1 { class class1 { public static form1 f; public void x() { f = new form1(); f.textbox1.text = "hello"; } } } i change textbox1 modifier public.
when f = new form1() create new form. if have instance of form1 open give 2 instances of form1. calling method on 1 of them won't affect other. have pass reference of form instance of class1 , call method on reference.
there different ways this. 1 pass reference argument x method:
public void x(form1 f) { f.textbox1.text = "hello"; } when call x can pass special variable this, object code associated with. pass instance of form1 x, x can use it.
c.x(this);
Comments
Post a Comment