Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use listBox Control in WinForm

Shulou Source: shulou.com Published: 2022-06-03 04:48:26 09月13日 Update

This article mainly introduces how to use listBox control in WinForm, which is very detailed and has certain reference value. Friends who are interested must finish it!

The use of namespace _ 13.ListBox control

{

Public partial class Form1: Form

{

Public Form1 ()

{

InitializeComponent ()

}

/ / create a new collection object to store the full path of the picture

List list = new List ()

Private void Form1_Load (object sender, EventArgs e)

{

/ / when the program is running, load the picture into listBox

/ / get the full path of the folder where the picture is located

String [] path = Directory.GetFiles (@ "C:\ Users\ Administrator.USER-20180925HC\ Desktop\ pic", "* .jpg")

/ / load the picture into listBox for (int I = 0; I < path.Length; iTunes +) {/ / get the file name string fileName = Path.GetFileName (path [I]); listBox1.Items.Add (fileName) through a loop; / / add the full path of the picture to the List generic collection list.Add (path [I]) }} private void listBox1_DoubleClick (object sender, EventArgs e) {/ / double-click the listBox picture name, and the right pictureBox displays the corresponding picture pictureBox1.Image = Image.FromFile (listBox1.SelectedIndex]);}}

}

The above is all the content of the article "how to use listBox controls in WinForm". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Picture control path content file article value interest right object guy partner location file name folder more knowledge program industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft MariaDB vpn Linux Shulou Information