如何从停靠表单访问数据?
我使用 http://sourceforge.net/projects/dockpanelsuite/ 作为我的停靠控件应用程序,我添加了一个表单作为对接容器,我需要从中访问主表单中的字符串。我只是闲逛,看看是否可以使用(Owner as MainWindow)加载它,但它不起作用。
for (int i = 0; i < (Owner as MainWindow).str.Count; i++)
{
MessageBox.Show("A");
}
我总是在第一行收到错误“对象引用未设置到对象的实例”。有什么方法可以从停靠表单访问字符串 str (顺便说一句,它是公共字符串)?
如果不清楚,请告诉我。
I'm using http://sourceforge.net/projects/dockpanelsuite/ as a docking control in my application and I have added a form as a docking container, and from it I need to access a string from the main form. I was just messing around to see if I could load it using (Owner as MainWindow), but it did not work.
for (int i = 0; i < (Owner as MainWindow).str.Count; i++)
{
MessageBox.Show("A");
}
I always get an error on the first line "Object reference not set to an instance of an object." Is there any way I can access the string str (it is a public string btw) from the docked form?
If it's unclear please let me know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建此表单(您的对接容器)时传递 MainForm 的引用。
例如,
在对接容器中添加一个构造函数:
这样您就可以在创建此表单时将 MainForm 引用传递给该表单:
并使用
GUImainform
访问此对接表单内的 MainForm。Pass a ref of the MainForm when you create this form (your docking container).
e.g.
add a constructor in your docking container:
so you can pass MainForm ref to this form when its created:
and access your MainForm inside this docking form with
GUImainform
.