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!!!
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";
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,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With