Martijn van Dru Posted August 20, 2003 Posted August 20, 2003 Hello all I have the following problem. How can 2 forms interact wich eachother? Public Class Form1 Inherits System.Windows.Forms.Form Public myForm2 As New Form2() Public nData As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click myForm2.Show() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox1.Text = nData End Sub End Class Public Class Form2 Inherits System.Windows.Forms.Form Public nData As Integer Public myForm1 As New Form1() Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click myForm1.nData = TextBox2.Text End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.Close() End Sub End Class In Form1 I create an instance of Form2. In Form2 I fill in an integer in textbox2 (nData). Now is my problem that I want that number nData in textbox1 on Form1, but I don't know how to do it. I don't wanna make a new instance of Form1, because then I have 2 different instances of Form1. Does somebody know in wich direction I have to search for my (simple?) problem? thank you Quote
Administrators PlausiblyDamp Posted August 20, 2003 Administrators Posted August 20, 2003 http://www.xtremedotnettalk.com/showthread.php?s=&threadid=75079&highlight=form1+form2 http://www.xtremedotnettalk.com/showthread.php?s=&threadid=75526&highlight=form1+form2 Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Leaders dynamic_sysop Posted August 20, 2003 Leaders Posted August 20, 2003 try this... Public Class Form1 Inherits System.Windows.Forms.Form Public myForm2 As New Form2() Public nData As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '/// Me.AddOwnedForm(myForm2) '/// add this line in form1 '/// myForm2.Show() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox1.Text = nData End Sub End Class Public Class Form2 Inherits System.Windows.Forms.Form Public nData As Integer Public myForm1 As Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '/// myForm1 = Me.Owner '/// add this in Form2. '///// myForm1.nData = TextBox2.Text End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.Close() End Sub End Class Quote
Leaders dynamic_sysop Posted August 20, 2003 Leaders Posted August 20, 2003 you beat me to it PlausiblyDamp ;) Quote
*Experts* mutant Posted August 20, 2003 *Experts* Posted August 20, 2003 You could also setup a class with shared members so you wouldnt have to use the Owner property and you would not have a problem accessing the form instances from anywhere in the program. Quote
Martijn van Dru Posted August 21, 2003 Author Posted August 21, 2003 Perfect that works, thanks for help Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.