将变量从主表单传递到输入表单 [英] Passing variables from main form to input form

查看:25
本文介绍了将变量从主表单传递到输入表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的问题.我有一个主表单,然后是一个启动表单,我可以从中选择一个新的 3D 模型来生成.从启动表单中选择新的 3D 模型时,我想首先检查我之前处理的模型是否已保存.我只是想使用委托将一个布尔值从主窗体传递给启动窗体,但我似乎无法访问主窗体或其任何变量.我认为这很简单:<code>frmMain myForm = new frmMain();</code>,但是在智能感知中输入 frmMain 不会显示任何内容.

I have a simple question. I have a main form, and then a startup form from where I can select a new 3D model to generate. When selecting a new 3D model from the startup form, I want to check first whether the previous model I worked on has been saved or not. I simply want to pass a boolean value from the main form to the startup form using a delegate, but I can't seem to access the main form or any of its variables. I thought it would be as simple as saying: <code>frmMain myForm = new frmMain();</code>, but typing frmMain doesn't show up anything in intellisense.

有什么提示吗?

推荐答案

在主窗体上添加公共属性

Add a public property on your main form

public bool IsDirty
{
    get;set;
}

然后您可以在启动表单中访问 this.ParentForm.IsDirty

you can then access this.ParentForm.IsDirty in your startup form,

记得在显示启动表单时传递对主表单的引用... startupForm.showDialog(this);

remember to pass a reference to the main form when you show the startup form ... startupForm.showDialog(this);

这篇关于将变量从主表单传递到输入表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆