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. Passing information between forms

Passing information between forms

Scheduled Pinned Locked Moved Visual Basic
4 Posts 3 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.
  • P Offline
    P Offline
    pj4FarEweDsf
    wrote on last edited by
    #1

    Looking for code to pass information from Form2.textbox1 back to Form1.label1 Process - Press Form1.button1 to show Form2, Enter information into Form2.textbox1, Press Form2.button1 to display information from Form2.textbox1 to Form1.label1. Thnaks in Advance! Form1 consists of Label1 Button1 For2 consist of textbox1 Button1

    N R 2 Replies Last reply
    0
    • P pj4FarEweDsf

      Looking for code to pass information from Form2.textbox1 back to Form1.label1 Process - Press Form1.button1 to show Form2, Enter information into Form2.textbox1, Press Form2.button1 to display information from Form2.textbox1 to Form1.label1. Thnaks in Advance! Form1 consists of Label1 Button1 For2 consist of textbox1 Button1

      N Offline
      N Offline
      Nick Seng
      wrote on last edited by
      #2

      The simplest way is to set the access modifier of the textbox to public or friend, then set label1.text = textbox1.text


      "if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler. Support Bone It's a weird Life

      1 Reply Last reply
      0
      • P pj4FarEweDsf

        Looking for code to pass information from Form2.textbox1 back to Form1.label1 Process - Press Form1.button1 to show Form2, Enter information into Form2.textbox1, Press Form2.button1 to display information from Form2.textbox1 to Form1.label1. Thnaks in Advance! Form1 consists of Label1 Button1 For2 consist of textbox1 Button1

        R Offline
        R Offline
        rubdub
        wrote on last edited by
        #3

        just a thought..dont u hav to use inheritance to do this sorta thing?...I'm actully looking to do same thing as well but with no luk so far..:( rubdub :)

        P 1 Reply Last reply
        0
        • R rubdub

          just a thought..dont u hav to use inheritance to do this sorta thing?...I'm actully looking to do same thing as well but with no luk so far..:( rubdub :)

          P Offline
          P Offline
          pj4FarEweDsf
          wrote on last edited by
          #4

          Here it is - Some background info for you that was given to me in the C# area [Google on "Mediator pattern" and "MVC" (or "Model-View-Controller"). If you learn how to use these patterns, you'll never get stuck like this again; your code won't need tricks like passing a form to another form. I recommend "Design Patterns" by the Gang of Four.] I just went to Microsoft ans sought out "Model-View-Controller" As for the code. A no brainer once you do it, Key words "once you do it" Once you have placed this very generic code in the forms and "Shared" class, go to project properties and set the startup object to "Global" - this is you shared class, you can use this class or whatgever class you use for application prep, tracings and logs. Option Strict On Option Explicit On Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Global.postF2() End Sub End Class Option Strict On Option Explicit On Public Class Form2 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Hide() Global.postF1(TextBox1.Text) End Sub End Class Option Strict On Option Explicit On Public Class Global Public Shared f1 As Form1 Public Shared f2 As Form2 Public Shared Sub main() f1 = New Form1 Application.Run(f1) End Sub Public Shared Function postF2() As String f2 = New Form2 f2.Show() End Function Public Shared Function postF1(ByVal post As String) As String f1.Label1.Text = post End Function

          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