简体   繁体   English

从列表框中显示消息框中的信息

[英]Displaying information in messagebox from listbox

I am writing a program that requires me to select a home address from a listbox.我正在编写一个程序,需要我从列表框中选择一个家庭地址。 When i click on the display button a messagebox is supposed to appear and display the address and several other bits of information stored in an array list for that address.当我单击显示按钮时,应该会出现一个消息框,并显示地址和存储在该地址数组列表中的其他一些信息。 I am fairly unfamiliar with listboxes and can't figure out how to display all this information in a messagebox from one selection in a listbox.我对列表框相当陌生,无法弄清楚如何从列表框中的一个选择中在消息框中显示所有这些信息。

You can get the selected item value in a ListBox您可以在ListBox获取所选项目的值

string curItem = listBox1.SelectedItem.ToString();

you may handle the onClick event of your btn, then show information in a message box您可以处理您的 btn 的onClick事件,然后在消息框中显示信息

 MessageBox.Show (curItem );

More info for MessageBox here MessageBox 的更多信息在这里

or you can write或者你可以写

MessageBox.Show(listBox1.SelectedItem.ToString());

no need to initialize any variable if you do not need th如果不需要,则无需初始化任何变量

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

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