如何从停靠表单访问数据?

发布于 2024-09-28 18:23:02 字数 469 浏览 0 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心如狂蝶 2024-10-05 18:23:02

创建此表单(您的对接容器)时传递 MainForm 的引用。
例如,

在对接容器中添加一个构造函数:

MainForm GUImainform;
public dockingContainerForm(ref MainForm mymainform)
{
   GUImainform=mymainform;
}

这样您就可以在创建此表单时将 MainForm 引用传递给该表单:

dockingContainerForm dcForm=new dockingContainerForm (ref this);

并使用 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:

MainForm GUImainform;
public dockingContainerForm(ref MainForm mymainform)
{
   GUImainform=mymainform;
}

so you can pass MainForm ref to this form when its created:

dockingContainerForm dcForm=new dockingContainerForm (ref this);

and access your MainForm inside this docking form with GUImainform.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文