传递价值并保持表格打开 [英] Passing values and keeping forms opened

查看:60
本文介绍了传递价值并保持表格打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在那里,无论如何,我可以有一个form1(主屏幕)并打开第二个(form2),然后在表单1中传递一个值到表单2,哪里总是需要打开?< br $> b $ b

我尝试了什么:



i试图打开这两种形式但是然后我无法传递错误的值:构造函数需要1个参数

hi there, is there anyway that i can have a form1(main screen) and open a second one(form2), and later in form 1 pass a value to form 2, where as both always need to be opened?

What I have tried:

i have tried to open both forms but then i cant pass the values of a the error: constructor takes 1 argument

推荐答案

你可以做一些像你的第二个形式做一个公开您的变量类型并在主窗体中将其传递给它。我不是一个好的解释者,这将是我第一次回答某人的问题。希望它对你有所帮助。

You could do something like in your second form make a public your variable type and pass it like this in your main form. I'm not a good explainer and this would be my first try as answering someones question. Hope it helped you.
public partial class Form1 : Form // main form
{
        public Form2 form2 = new Form2();
        private void Form1_Load(object sender, EventArgs e)
        {
            form2.Show();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            form2.storage = Textbox1.text;
        }
}
public partial class Form2 : Form // form 2
{
     public string storage = "";
}


见这里:在两种表格之间传递信息,第1部分:父母对儿童 [ ^ ]


这篇关于传递价值并保持表格打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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