从另一种形式在列表框中添加项目 [英] add item in listbox from another form
本文介绍了从另一种形式在列表框中添加项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两种形式.form1有一个列表框.和form2有一个文本框和一个按钮.如果我在文本框中输入我的名字,然后单击添加按钮,那么我的名字应该添加在列表框中.
I have two form .form1 has a listbox. and form2 has a textbox and a button.if i write my name in textbox and click to add button then my name should add in list box.
推荐答案
嗨
你可以试试这个吗?
Hi
Can you try this.
Form1.cs
Form2 f2 = new Form2();
f2.ShowDialog();
public void UpdateListBox(string lstValue)
{
listBox1.Items.Add(lstValue);
}
Form2.cs
Form1 f1= (Form1)Application.OpenForms["Form1"];
f1.UpdateListBox(textBox1.Text);
这篇关于从另一种形式在列表框中添加项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文