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