0
我試圖從一個目錄中加載.JPEG圖像,並通過點擊按鈕將其加載到ListBox
,這是我實現的目標。但是,我需要將這些圖像放入PictureBox
。有人能指點我正確的方向嗎?這是我迄今爲止。將圖像從列表框加載到圖片框
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
DirectoryInfo dinfo = new DirectoryInfo(@"C:\cake");
FileInfo[] Files = dinfo.GetFiles();
foreach (FileInfo file in Files)
{
listBox1.Items.Add(file.Name);
}
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Add(@"C:\cake");
}
private void pictureBox1_Click(object sender, EventArgs e)
{
string[] x = System.IO.Directory.GetFiles(@"C:\cake", "*.jpeg");
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
for (int i = 0; i < x.Length; i++)
{
listBox1.Items.Add(x[i]);
}
}
}
由於生病嘗試! – bagel123