c# - Change Textfield from another class? -
i start out sourcecode:
form
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.io; using system.linq; using system.net.mail; using system.text; using system.text.regularexpressions; using system.threading; using system.threading.tasks; using system.windows.forms; namespace software { public partial class form1 : form { public form1() { initializecomponent(); } try { myclasstwo 2 = new myclasstwo(); two.putvalue(); } catch { messagebox.show("error!"); } } } myclasstwo
using system; using system.collections.generic; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace software { public class myclasstwo { form1 myform = new form1(); public void putvalue() { myform.textbox1.text = "hello"; } } } i want change content of textbox in myclassone. when doesnt work, nothing happens. can me that? updated code.
the form myclasstwo referring not same form 1 trying set text in. myclasstwo creating entirely new instance of form , setting text of that, never see.
without trying toooo hard, try this?
public class myclasstwo { public void putvalue(form1 myform) { myform.textbox1.text = "hello"; } } and
try { myclasstwo 2 = new myclasstwo(); two.putvalue(this); } the idea pass form want change text in, opposed creating new form inside of myclasstwo.
Comments
Post a Comment