.Net C# MDI Floating Childing windows

Using the latest WeifenLuo(Dock Panel Suite)  and I'm not very expirienced in MDI development. My problem is that my child windows need to update a StatusBar and ProgressBar on the Parent. When the child window is Docked on the Parent this is accomplished my just casting the MDIParent property on the Child window but I get an Cast error if the Child window is Floating.

Is there another way of referencing the parent when Floating the child window?
csalernoAsked:
Who is Participating?
 
Bob LearnedCommented:
My usual weapon of choice in that scenario would be to define an event, and add an event handler in the child windows, but I am not sure of the implementation details in your case.
0
 
ste5anSenior DeveloperCommented:
An event - as Bob wrote - is the easist solution. Another would be a message queue.
0
 
csalernoAuthor Commented:
Not sure how to write the event & handler for the Parent and Child window. Would you have any examples to point to?
0
 
Bob LearnedCommented:
The normal approach for a parent/child class structure would be something like this:

public class Parent
{
      public event EventHandler MyEvent;

      public void OnMyEvent(object sender, EventArgs e)
      {
           if (MyEvent != null)
               MyEvent(sender, e);
      }
}

public class Child
{
       public Child(Parent parent)
       {
            if (parent == null)
                throw new ArgumentNullException("parent");
            
            parent.MyEvent += new MyEventHandler();
       }

       private void MyEventHandler(object sender, EventArgs e)
       {
               ' The event was raised, so handle it.
       }
}

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.