2016-09-06 1 views
0

여기 코드는 내가 작성한 코드입니다. img.Image.FromFile(); 전체 경로를 작성했지만 Pics 폴더에서 사진을 선택해야합니다. 나는 DataGridView의 선택이 바뀌었을 때 내가 썼던 길을 의미한다. 나는 내 자신의 노트북에서만 사진을 본다.img.Image.FromFile()에서 올바른 경로 설정;

private void dataGridViewSearch_SelectionChanged(object sender, EventArgs e) 
{ 
    if (dataGridViewSearch.SelectedRows.Count == 0) return; 
    dataGridViewSearch.Visible = false; 

    if (dataGridViewSearch.CurrentCell.ColumnIndex == 0) 
    { 
     buttonB.Visible = true; 
     int n = dataGridViewSearch.CurrentRow.Index; 
     string imgName = arr2[n].Pic; 

     img = Image.FromFile("C:/Users/baghd/Summer2016/Desktop/1/Pics/" + imgName); 
     //img = Image.FromFile("Pictures/" + imgName); 

     pictureBox1.Image = img; 
     pictureBox1.Visible = true; 
    } 
    else { } 
     //C:/Users/baghd/Summer2016/Desktop/1/ 
} 

답변

0

당신은 모든 컴퓨터에 바탕 화면 경로를 얻을 수 Statis 클래스 Enviorment을 사용할 수 있습니다 : 당신은 당신이 때문에 슬래시의 그것의 앞에 @를 둘 필요가 경로를 쓸 때 또한

string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/1/Pics" + imgName; 

img = Image.FromFile(@"C:/Users/baghd/Summer2016/Desktop/1/Pics/" + imgName); 

또는

img = Image.FromFile("C://Users//baghd//Summer2016//Desktop//1//Pics//" + imgName); 

희망이 도움이 ...

+1

고마워, 너무 늦게 답변 해 주셔서 죄송합니다. –