Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. change the caller form based on the result of the called form

change the caller form based on the result of the called form

Scheduled Pinned Locked Moved Visual Basic
question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hui2006
    wrote on last edited by
    #1

    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

    B 1 Reply Last reply
    0
    • H hui2006

      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

      B Offline
      B Offline
      Briga
      wrote on last edited by
      #2

      Different way of accomplishing it. Common one, and easiest, is: sub form1clickwhattever.... form2.show me.textbox1.text = form2.controlwithdata.text end sub

      H 1 Reply Last reply
      0
      • B Briga

        Different way of accomplishing it. Common one, and easiest, is: sub form1clickwhattever.... form2.show me.textbox1.text = form2.controlwithdata.text end sub

        H Offline
        H Offline
        hui2006
        wrote on last edited by
        #3

        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?

        B 1 Reply Last reply
        0
        • H hui2006

          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?

          B Offline
          B Offline
          Briga
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups