将变量从主窗体传递到输入窗体
我有一个简单的问题。我有一个主窗体,然后是一个启动窗体,我可以从中选择要生成的新 3D 模型。当从启动表单中选择一个新的 3D 模型时,我想首先检查我之前处理的模型是否已保存。我只是想使用委托将布尔值从主窗体传递到启动窗体,但我似乎无法访问主窗体或其任何变量。我认为这就像说: frmMain myForm = new frmMain();
一样简单,但是输入 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.
Any hints?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在主窗体上添加公共属性
,然后您可以在启动窗体中访问
this.ParentForm.IsDirty
,请记住在显示启动窗体时传递对主窗体的引用...
startupForm.showDialog(this);
Add a public property on your main form
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);
您的主窗体无法通过启动窗体访问。您必须将其存储到您想要使用它的地方可以访问的位置。
您也可以通过以下方式(以及其他方式:)来完成此操作,
确保将此类放在两种形式都可以访问的命名空间中。
现在,在您的 frmMain 表单中设置 CCurrent.Saved 的值并在启动表单中访问它。
Your main form is not accessible to Startup form.You have to store it to something that is accessible at a point where you want to use it.
You can do it by following way also ( along with other ways :)
make sure you put this class in namespace which is accessible to both the forms.
Now In your frmMain form set the value of CCurrent.Saved and access it in your startup form.
这是我的建议:
在主窗体中放置一个 3DModel 对象属性:
将您的启动窗体声明为对话框(如 OpenFileDialog)并执行如下操作:
您的启动窗体应具有如下界面:
Here's my suggestion:
place a 3DModel object property in your main form:
Declare your startup form as a Dialog ( like OpenFileDialog) and do something like this:
your startup form should have a interface like this: