2013-11-03 3 views
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]); 
     } 
    } 
} 

답변

0

같은 더 보일 것이다 ...

private void button1_Click(object sender, EventArgs e) 
    { 
     listBox1.Items.Clear(); 
     DirectoryInfo dinfo = new DirectoryInfo(@"C:\cake"); 
     FileInfo[] Files = dinfo.GetFiles("*.jpeg"); 
     listBox1.Items.AddRange(Files); 
     listBox1.DisplayMember = "FileName"; 
    } 

    private void listBox1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     if (listBox1.SelectedIndex != -1) 
     { 
      FileInfo fi = (FileInfo)listBox1.SelectedItem; 
      pictureBox1.ImageLocation = fi.FullName; 
     } 
    } 
0

이미지 위치를 사용하여 그림 상자에 이미지를 표시하는 방법을 찾고 있어야합니다.

pictureBox1.ImageLocation("Image Location"); 

사용자가 이미지를 선택할 수있게하려면 다음과 같이하십시오.

 OpenFileDialog dlg = new OpenFileDialog(); 
     dlg.Filter = "JPEG FILES(*.jpeg)"; 
     if (dlg.ShowDialog() == DialogResult.OK) 
     { 
      pictureBox1.ImageLocation(dlg.FileName.ToString()); 
     } 
+0

덕분에 병이 시도! – bagel123

관련 문제