Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何调用picturebox的文件_C#_Windows_Forms_Picturebox - Fatal编程技术网

C# 如何调用picturebox的文件

C# 如何调用picturebox的文件,c#,windows,forms,picturebox,C#,Windows,Forms,Picturebox,我有一个包含6个数组的表单,每个数组有15个元素。我写它们的方式是,如果我搜索我自己(作为string[]name数组中的第一个元素),表单将加载每个数组的第一个元素:年龄、性别、爱好、照片等。 这是我正在使用的pictureBox代码的一部分 //I have more arrays here, like: Name,Gender,Age,Hobby,Place & Talent string[] photo=new string[] { "764.jpg", " 765.jpg",

我有一个包含6个数组的表单,每个数组有15个元素。我写它们的方式是,如果我搜索我自己(作为string[]name数组中的第一个元素),表单将加载每个数组的第一个元素:年龄、性别、爱好、照片等。 这是我正在使用的pictureBox代码的一部分

//I have more arrays here, like: Name,Gender,Age,Hobby,Place & Talent
string[] photo=new string[] { "764.jpg", " 765.jpg", " 766.jpg", " 767.jpg"," 765.jpg", " 767.jpg", " 768.jpg", " 769.jpg", " 770.jpg", " 771.jpg",  " 772.jpg", " 773.jpg", " 774.jpg", " 775.jpg", " 776.jpg"};

string name="",gender="",place="",warning=""; int age = 0; string image="";

for (int i = 0; i < 15; i++)
        {
            if (textBox6.Text == emri[i])
                  {
                      //I applied every element of every array to the declared variables
                      image = photo[i];
                      j++;
                  }
            if (j == 1)
                  {
                       //Associated the textBoxes with the variables
                       pictureBox1.Image = Image.FromFile(@"C:\Users\NComputers\Documents\Visual Studio 2015\Projects\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\Sony Xperia\" + image);

                  }
            else
                  { 
                       MessageBox.Show("Person not found!"); 
                  }
//我这里有更多数组,比如:姓名、性别、年龄、爱好、地点和天赋
string[]photo=新字符串[]{“764.jpg”、“765.jpg”、“766.jpg”、“767.jpg”、“765.jpg”、“767.jpg”、“768.jpg”、“769.jpg”、“770.jpg”、“771.jpg”、“772.jpg”、“773.jpg”、“774.jpg”、“775.jpg”、“776.jpg”};
字符串名称=”,性别=”,位置=”,警告=”;int年龄=0;字符串图像=”;
对于(int i=0;i<15;i++)
{
if(textBox6.Text==emri[i])
{
//我将每个数组的每个元素应用于声明的变量
图像=照片[i];
j++;
}
如果(j==1)
{
//将文本框与变量关联
pictureBox1.Image=Image.FromFile(@“C:\Users\NComputers\Documents\Visual Studio 2015\Projects\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\Sony Xperia\”+Image);
}
其他的
{ 
MessageBox.Show(“找不到人!”);
}

虽然没有显示错误,但图片无法加载。所有其他项目都正常工作。帮助?

如何知道没有错误?将代码放入try/catch块进行验证。您指向bin\Debug查找图像,是否确定这是正确的路径?是否指向同一目录?下面是pictureBox代码的一部分这是什么事件?你使用了调试器吗?在这里发布之前,你应该一直使用调试器!!!那里有什么发现???@Johnnymapp我试过了,但我的程序没有捕获到any@wentimo是的,这是我在另一个线程上看到的。我还转到解决方案资源管理器,单击“显示所有文件”,bin,Debug,sonyxperia,并将它们包含到我的项目中。我可以尝试另一种方法,但我怀疑它是否有效