How to fire an event from the MDI parent to a child window?

G

Guest

Can anyone tell me how an MDI parent can fire an event that the child window
can pick up?

We have a MDI parent window containing 2 child windows (named 1 and 2).
Child window 2 updates and fires an event to say it has updated that the main
MDI parent can pick up on. I cannot find a way for the MDI parent to say to
Child window 1 that Child Window 2 has been updated?

Any help would be appreciated?
Thanks
mike
 
A

AMDRIT

There are a number of ways, more are prolly more correct than the one I
propose.

I like to keep the state of the data seperate from the forms. So in this
case I would create a state object that is shared among the forms. I then
register to receive event notification from this shared object. There are a
couple of ways to do this as well. Here is one way.

public class DataState

event Dataupdated(sender as object, e as eventargs)

private shared objDataState as DataState

shared Sub new
objdatastate = new DataState
end sub

public shared readonly property Instance as DataState
get
return pobjdatastate
end get
end property

end Class

public class Form1
public sub new
'after initialize
addhandler datastate.instance.DataUpdate, addressof OnDataUpdate
end sub

private sub OnDataUpdate(sender as object, e as eventargs)
'Handle event here
end sub

end class


The IssueVision project on www.windowsforms.com has another way of
implementing notifications between forms.
 
G

Guest

Mike,

I had never tried that before, so my code might not be the best way to
accomplish this. However, this worked for me:

On my mdi form, Form1:

Public Event MDIEvent()

On my child form, Form2:

Private WithEvents mdiForm As Form1

Private Sub Form2_Load(...) Handles MyBase.Load

Me.mdiForm = Me.MdiParent

End Sub

Private Sub mdiForm_MDIEvent() Handles mdiForm.MDIEvent

MsgBox("MDIEvent handled in child form")

End Sub

Kerry Moorman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top