如何将列表框值以另一种形式转移到列表框? [英] How to trasfer listbox value to listbox in another form?

查看:57
本文介绍了如何将列表框值以另一种形式转移到列表框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将列表框值以另一种形式转移到列表框?

我希望如何在单击按钮传输时转移并以新形式打开新表单+列表框

How to trasfer listbox value to listbox in another form?
I want how to transfer when click button transfer and open new form + listbox in new form

推荐答案

您可以尝试这样的事情:



You could try something like this:

private void button1_Click(object sender, EventArgs e)
    {
         Form2 frm = new Form2(listBox1);
         frm.Show();
    }





然后在第二种形式(form2)中,使用参数类型列表框重载构造函数。 />
在这里,您可以在第二个表单上将项目添加到列表框中。





And then in the 2nd form (form2), you overload the constructor with a parameter typed listbox.
And here you add the items to you listbox on the 2nd form.

public Form2(ListBox lsb)
        {
            InitializeComponent();
            foreach (var item in lsb.Items)
            {
                listBox1.Items.Add(item);
            }
        }


类似于:

Something like:
form2.listBox1.Items.Add(form1.listbox1.Items.Item[0]);


这篇关于如何将列表框值以另一种形式转移到列表框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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