4

几天来我一直在寻找解决方案,但找不到简单的答案。我已经尝试了一些在互联网上找到的示例(代表、属性,甚至打破 OOP 公开所有内容),但这些似乎都不起作用。有人可以为以下问题编写一个最简单的代码:

我有 MDI 父窗体和子窗体。MDI 父窗体具有状态条标签。子窗体有一个按钮。我要做的就是在单击子表单按钮时更新 MDI 标签。

谢谢!!!

4

2 回答 2

7

这不是最好的解决方案。但是,这是最简单的一个:

1-将状态条标签的访问修饰符更改为公共。

2-将父表单拆箱为其真实类型,以便能够访问标签:

((ActualMdiParentFormType) this.MdiParent).statusStripLabel.Text = "Value";
于 2011-04-16T09:22:10.943 回答
1

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,

于 2014-08-28T08:30:04.167 回答