c# - How to get Textbox information from one user control to another -
i have 2 user controls in windows form application. in first user command have 1 "textbox" , 1 "save" button. , have "textbox" in user control. when click "save" button in frist user command whatever value in "textbox" in user command 1 has display in user command "textbox".
i have tried this
namespace project { public partial class ucsample : usercontrol { private double transfervolume; public double transfervolume { { homecoming transfervolume; } set { transfervolume = value; } } public ucsample() { initializecomponent(); } private void btnsave_click(object sender, eventargs e) { transfervolume = double.parse(txtsamplevolume.text); } } }
in user command trying write logic shown below.
namespace project { public partial class ucsettings : usercontrol { ucsample samplevolume = new ucsample(); public ucsettings() { initializecomponent(); } private void txtvolumemin_textchanged(object sender, eventargs e) { txtvolumemin.text = samplevolume.transfervolume.tostring(); } } }
please can 1 help me error doing here. using property transfer value. not able figure out mistake. or other best way this.
it looks have code reversed. let's assume text box in first command named foo
(because don't see code) , let's assume instance of ucsettings
command on form named ucsettingsinstance
:
in ucsample
control:
public event eventhandler textchanged; private void foo_textchanged(object sender, eventargs e) { if (this.textchanged != null) { this.textchanged(sender, e); } }
in form consume new event:
private void ucsettingsinstance_textchanged(object sender, eventargs e) { ucsettingsinstance.minimumvolume = ucsampleinstance.transfervolume; }
now need add together new property ucsettings
:
public double minimumvolume { { homecoming minimumvolume; } set { minimumvolume = value; txtvolumnmin.text = minimumvolume.tostring(); } }
and when value changed in first command can set value in sec control.
c# winforms c#-4.0
No comments:
Post a Comment