Communication between different forms

帅比萌擦擦* 提交于 2019-11-30 15:10:55

We'ved used something called the Event Pattern successfully in several Winform applications. Here's a good link that will help you get started.

You can create events in one form and then register for those events in the other form. You can also simply access properties from one form to the other. For example maybe in the constructor of the second form, you would pass a variable for the first form.

It sounds like what you're looking for are events though. When some event happens any delegate that is registered will be called.

There is a tutorial on MSDN for events here.

all depends on what you want to communicate.

Let's say it is configuration data; You could create a static property on main form called Settings, which would expose your object. Than all forms would see that same Settings instance, and all would see any changes.

for extra credit you could implement INotifyPropertyChanged, and have it trigger an event. that way all forms looking at Settings would be notified if anything changed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!