Leaders dynamic_sysop Posted July 1, 2003 Leaders Posted July 1, 2003 Hi guys , i've been working on an easier way to load a form and send info back to the starting form / another form. there's no need to modify the Sub New really , this is all you need to do : from the form you already have open to call the second form : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim frmKid As New Form3() Me.AddOwnedForm(frmKid) frmKid.Show() End Sub from the second form ( eg: Form2 ) to set some text in Form1's Textbox : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim frmBoss As Form1 = Me.Owner frmBoss.TextBox1.Text = "test" '///put some text in Form1's textbox. End Sub i think this may save a bit of messing for people :) Quote
yan19454 Posted July 2, 2003 Posted July 2, 2003 I tried I got an error message . An unhandled exception of type 'System.InvalidCastException' occurred in WindowsApplication1.exe Additional information: Specified cast is not valid. Quote
Krijn Posted July 2, 2003 Posted July 2, 2003 Hi, I really don't think this is the right answer in .NET. Maybe it would be correct in vb6 but this is totally not compatible with the OO - language where .NET stands for. To do it in a more .NET way I suggest you create some events for setting some text in the second form. example : Public Event MustSetText(Sender as object, Msg as string) In the button click event off your second form raise the event : Raise event MustSetText(Me, "Hi from form2!") Then catch the event in the first form On_Form2_MustSetText(Sender as object, Msg as string) Me.textBox1.text = Msg 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.