How to change mdi status label label from child form

I have been looking for a solution for a couple of days, but cannot find a simple answer. I tried a number of examples found on the Internet (delegates, properties, even if OOP makes everything public), but none of them seem to work. Can someone please write the simplest possible code for the following problem:

I have a parent MDI form and a child form. The parent MDI form has a status label. The child form has a button. All I want to do is update the MDI label when a child form button is clicked.

Thanks!!!

+4
source share
2 answers

This is not the best solution. However, this is the simplest of them:

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

2- Disconnect the parent form to its real type in order to have access to the label:

((ActualMdiParentFormType) this.MdiParent).statusStripLabel.Text = "Value"; 
+6
source

There is another solution that should create an event in the child window and register the parent window for this event. If an event occurs, the parent window will be notified, and in the corresponding event handler of the parent window we can update the OUR control.

This is a more like MVVM approach.

Check out these links for more information:

Pass value between forms using events

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

MVVM: a tutorial from start to finish?

Hope this helps,

+1
source

All Articles