addicktz
asked on
MDI Forms 1/2 - Working Between
Ok, So I am clueless on how to work between forms in vb.net, especially mdi forms, cany anyone give me any suggestions on how I would go about sending a string to the mdiparent form ?
ASKER
how bout i raise it to 500 for all three =)
Here is the first method using events. The mdiChild form has a TextBox and a Button. When the button is pressed, the text from the textbox is sent the the parent via mdiChilds custom event. I have excluded all the control declarations so it is easy to see how the code works:
Public Class mdiParent
Inherits System.Windows.Forms.Form
Private Sub mdiParent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim c As New mdiChild
c.MdiParent = Me
AddHandler c.newValue, AddressOf Me.child_newValue
c.Show()
End Sub
Private Sub child_newValue(ByVal child As mdiChild, ByVal someValue As String)
MsgBox(someValue, MsgBoxStyle.Information, "newValue() event received in mdiParent")
End Sub
End Class
Public Class mdiChild
Inherits System.Windows.Forms.Form
Public Event newValue(ByVal child As mdiChild, ByVal someValue As String)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
RaiseEvent newValue(Me, TextBox1.Text)
End Sub
End Class
Public Class mdiParent
Inherits System.Windows.Forms.Form
Private Sub mdiParent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim c As New mdiChild
c.MdiParent = Me
AddHandler c.newValue, AddressOf Me.child_newValue
c.Show()
End Sub
Private Sub child_newValue(ByVal child As mdiChild, ByVal someValue As String)
MsgBox(someValue, MsgBoxStyle.Information, "newValue() event received in mdiParent")
End Sub
End Class
Public Class mdiChild
Inherits System.Windows.Forms.Form
Public Event newValue(ByVal child As mdiChild, ByVal someValue As String)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
RaiseEvent newValue(Me, TextBox1.Text)
End Sub
End Class
Here is the second method where the child changes a variable in the parent:
Public Class mdiParent
Inherits System.Windows.Forms.Form
Public someValue As String
Private Sub mdiParent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim c As New mdiChild
c.MdiParent = Me
c.Show()
End Sub
End Class
Public Class mdiChild
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mdiP As mdiParent = CType(Me.MdiParent, mdiParent)
mdiP.someValue = TextBox1.Text
MsgBox(mdiP.someValue, MsgBoxStyle.Information, "someValue on mdiParent changed")
End Sub
End Class
Public Class mdiParent
Inherits System.Windows.Forms.Form
Public someValue As String
Private Sub mdiParent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim c As New mdiChild
c.MdiParent = Me
c.Show()
End Sub
End Class
Public Class mdiChild
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mdiP As mdiParent = CType(Me.MdiParent, mdiParent)
mdiP.someValue = TextBox1.Text
MsgBox(mdiP.someValue, MsgBoxStyle.Information, "someValue on mdiParent changed")
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you =)
~IM