简体   繁体   English

c#Winforms-在类/ dll之间传递控件引用

[英]c# Winforms - Passing control references between classes/dll's

I have written a piece of software that supports plugin architecture. 我写了一段支持插件架构的软件。 On the main GUI is a TextBox that I use to update the user with the status of the processes. 在主GUI上是一个TextBox,我用它来更新用户的进程状态。

When I load a plugin, is it bad practice to pass a reference for that Textbox through to the plugin so that it can update it from within. 当我加载插件时,将文本框的引用传递给插件以使其可以从内部进行更新是一种不好的做法。 Is this too highly coupled? 耦合度太高了吗? Would it better practise with events? 更好地实践事件吗?

Thanks. 谢谢。

I would suggest that you create an interface for communications between the plugin and its host. 我建议您创建一个用于插件与其主机之间通信的接口。 That would have an UpdateStatus method, and the implementation would update the textbox. 那将有一个UpdateStatus方法,并且实现将更新文本框。

If you really only have one thing to do (updating the status) then you could use a simple delegate... but it seems likely that you may need more operations over time. 如果您真的只有一件事要做(更新状态),则可以使用简单的委托...但是随着时间的推移,您似乎可能需要更多的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM