How to change mdi statusstrip label from a child form

6.8k Views Asked by At

I've been searching for a solution for couple of days now, but can't find a simple answer. I've tried a number of examples found on internet (delegates, properties, even breaking OOP making everything public) but none of these seem to work. Can someone please write a simplest possible code for the following problem:

I have MDI parent form, and a child form. MDI parent form has a status-strip label. Child form has a button. All I want to do is update the MDI label on click of child form button.

Thanks!!!

2

There are 2 best solutions below

3
On BEST ANSWER

It is not the best solution. However, it is the easiest one:

1- Change the access modifier of the status-strip label to public.

2- Unbox the parent form to its real type to be able to access the label:

((ActualMdiParentFormType) this.MdiParent).statusStripLabel.Text = "Value";
0
On

There is another solution which is to create an event in the child window and register the parent window to that event. In case that the event fires, the parent window will be notified and in the corresponding event handler of the parent window we can update OUR control.

This is a more "MVVM" like approach.

Check these links for more information:

Pass value between forms using events

http://www.c-sharpcorner.com/uploadfile/yougerthen/mvvm-implementation-for-windows-forms/

MVVM: Tutorial from start to finish?

Hope that helps,