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

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

问题描述

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



任何提示?

解决方案

在主窗体上添加公共资源

  public bool IsDirty 
{
get; set;
}

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



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


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.

Any hints?

解决方案

Add a public property on your main form

public bool IsDirty
{
    get;set;
}

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

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

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

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