[英]To access controls of a form from a different project in same solution
I want access controls in a form which is in a different project in the same solution.I have designed in a such a way that one solution has different projects in it. 我希望访问控制的形式位于同一解决方案的不同项目中。我设计的方式是,一个解决方案中包含不同的项目。
I have tried the following code. 我尝试了以下代码。
Form form = (Form)Application.OpenForms["frm"];
if (form != null)
{
Button cs = (Button)((form.Controls["btn"]);
cs.Enabled = false;
}
Using this code am able to locate the form,but am not able to access controls from it."cs" is returning null value and throwing "null refernce exception error".What could be the possible error and how should I modify the code.Its a windows application using c# visual studio 2010. Any suggestion would be of great help. 使用此代码能够找到该窗体,但无法从中访问控件。“ cs”返回空值并抛出“空引用异常错误”。可能是什么错误,我应该如何修改代码。它是使用c#visual Studio 2010的Windows应用程序。任何建议都会有很大帮助。 Thanks
谢谢
Ignoring why you might want to do this in the first place, I would recommend: 我不建议您首先为什么要这样做,我建议:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.