简体   繁体   English

将数据从列表框发送到其他表单上的标签

[英]Send data from a listbox to a label on another form

I have a menu where I can add items to a list box using an add button. 我有一个菜单,可以在其中使用添加按钮将项目添加到列表框。

I then have a button to send the order so to speak. 我可以按一下按钮发送订单。

The button to send the order I need it to be able to send what is in the list box to a label (or even list box?) on another form. 发送订单的按钮我需要它能够将列表框中的内容发送到另一种形式的标签(甚至列表框?)上。

So far I am only able to write my own text in a text box and then send it to a label on another form, I can't work out how to use what is in the list box to send to that label. 到目前为止,我只能在文本框中编写自己的文本,然后将其发送到其他表单上的标签,但我无法弄清楚如何使用列表框中的内容发送到该标签。

You can do it like this: 您可以这样做:

  • In your first form with the listbox 在带有列表框的第一个表单中

     Form2 f = new Form2(listBox1); f.Show(); 
  • In second form with label 带标签的第二种形式

     public Form2(ListBox listy) { InitializeComponent(); foreach (var item in listy.Items) { label1.Text += item.ToString(); } } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM