Jump to content
Xtreme .Net Talk

Recommended Posts

  • Leaders
Posted

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 :)

Posted

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.

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...