如何从子窗体更改 mdi statusstrip 标签
我几天来一直在寻找解决方案,但找不到简单的答案。 我尝试了在互联网上找到的许多示例(委托、属性,甚至打破 OOP 使所有内容公开),但这些似乎都不起作用。 有人可以为以下问题编写一个最简单的代码吗:
我有 MDI 父窗体和子窗体。 MDI 父窗体有一个状态条标签。子窗体有一个按钮。我想要做的就是在单击子表单按钮时更新 MDI 标签。
谢谢!!!
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!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是最好的解决方案。然而,这是最简单的:
1- 将状态条标签的访问修饰符更改为 public。
2- 将父表单拆箱为其真实类型,以便能够访问标签:
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:
还有另一种解决方案,即在子窗口中创建事件并将父窗口注册到该事件。如果事件触发,父窗口将收到通知,并且在父窗口的相应事件处理程序中我们可以更新我们的控件。
这是一种更像“MVVM”的方法。
检查这些链接以获取更多信息:
使用以下方式在表单之间传递值事件
http://www. c-sharpcorner.com/uploadfile/yougerthen/mvvm-implementation-for-windows-forms/
MVVM:从头到尾的教程?
希望有帮助,
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,