将值从父窗体传递到子窗体? [英] Pass value from parent form to child form?
本文介绍了将值从父窗体传递到子窗体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将父表单中设置的值传递给第二个表单.我在父表单中创建了一个带有 get 部分的属性.
I'm trying to pass a value set in my parent form to a second form. I created a property with a get part in the parent form.
我不想做这样的事情:
Form2 secondForm = new Form2(value);
这是一个已经存在的表单,我不想每次要传递一个值时都继续创建一个新表单.
It is an already exiting form and I don't want to keep creating a new form every time I want to pass a value.
推荐答案
看这个例子.
1-创建一个窗体应用程序,在 Form1 中声明一个公共字符串全局变量,使用这个变量我们可以将值从 Form1 传递给 Form2.
1-Create a window form application,Declare a public string global variable in Form1 , using this variable we can pass value from Form1 to Form2.
2-现在在form2中,为Form1创建一个对象并使用这个对象获取值.
2-Now in form2 ,Create a object for Form1 and Get the value using this object.
看图
这篇关于将值从父窗体传递到子窗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文