change the caller form based on the result of the called form
-
Hello, I am coding a text editor program. I creat my main form with a menu. While the user hit a menu item, a different form would come out and ask for input. After that, I would like the change reflected in the main form, say, TextBox1 in the main form. Can somebody give suggestions? Best, Hui
-
Hello, I am coding a text editor program. I creat my main form with a menu. While the user hit a menu item, a different form would come out and ask for input. After that, I would like the change reflected in the main form, say, TextBox1 in the main form. Can somebody give suggestions? Best, Hui
-
Different way of accomplishing it. Common one, and easiest, is: sub form1clickwhattever.... form2.show me.textbox1.text = form2.controlwithdata.text end sub
Thanks for the reply. I tried to use the code in my program. However, it does not work. I would like the me.textbox1.text get changed after the user click on an OK button in the 2nd form. The code above replaces the textbox1.text with a blank string, since the user has not filled out the info yet. I guess that I need to refer to the caller (main form) in the called form (child form), but I don't know how to refer to the main form in the child form. In Visual Basic 6, I think I can just call its name but not in Visual Basic .Net. Any suggestions?
-
Thanks for the reply. I tried to use the code in my program. However, it does not work. I would like the me.textbox1.text get changed after the user click on an OK button in the 2nd form. The code above replaces the textbox1.text with a blank string, since the user has not filled out the info yet. I guess that I need to refer to the caller (main form) in the called form (child form), but I don't know how to refer to the main form in the child form. In Visual Basic 6, I think I can just call its name but not in Visual Basic .Net. Any suggestions?
Well my code has an error or better it was missing the form2.showdialog (so that the next line is executed only after the form2 has been hidden/closed with the button). So if you replace .show with .showdialog then it works. Anyway if you want a more precise answer you should provide more precise informations. Which versione of FW are you using 1.x or 2? VS2003 or VS2005. In VS2003 you can refer to the calling form only if it's public declared. Module x public fmain as new frmMain end module then in the form2 button click event handler: fmain.textbox1.text = .... In VS2005 in most cases you can state immediatly the form without instancing it. This means you can have a direct access to frmMain (considering the previous example) unless you're running an instance created by you (than you fallback in the former case). Another way of doing it is by raising an event. In form2 you'll have: ... raisevevent OKClicked() and in form1 private sub ClickOnForm2() handles frm2.OKClicked me.textbox1.text = frm2.textbox1.text end sub or using parameters ... public class frm2eventargs inherits eventargs public t as string end class on form2 before you raise the event... dim e as new frm2eventargs e.t = (text to pass) raiseevent OKClicked(me,e) and then on the mainform private sub frm2OKClick(sender as object,e as frm2eventargs) handles frm2.OKClicked me.textbox1.text = t end sub So as you can see lot of options depending on the approach you want and what you're using.