Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change mdi statusstrip label from a child form

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!!!

like image 936
Alex Avatar asked Feb 25 '23 12:02

Alex


2 Answers

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";
like image 62
Akram Shahda Avatar answered Feb 27 '23 02:02

Akram Shahda


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,

like image 40
Ramon Araujo Avatar answered Feb 27 '23 01:02

Ramon Araujo