Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.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# 当我重新运行应用程序时,图片框不显示上次上载的图像_C#_.net_Winforms_Image_Picturebox - Fatal编程技术网

C# 当我重新运行应用程序时,图片框不显示上次上载的图像

C# 当我重新运行应用程序时,图片框不显示上次上载的图像,c#,.net,winforms,image,picturebox,C#,.net,Winforms,Image,Picturebox,嗨,我有picturebox,当我点击按钮时显示图像,它很好 但是当我关闭应用程序并再次运行应用程序时,它不会显示最后上传的图像,这是我的代码 public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { open

嗨,我有picturebox,当我点击按钮时显示图像,它很好

但是当我关闭应用程序并再次运行应用程序时,它不会显示最后上传的图像,这是我的代码

 public partial class Form1 : Form
 {
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        openFileDialog1.FileName = @"D:\";

        openFileDialog1.Filter = "png files (*.png)|*.png|jpg files (*.jpg)|*.jpg";
        openFileDialog1.CheckFileExists = true;
        openFileDialog1.CheckPathExists = true;

        if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
        {


            Image image1 = Image.FromFile(openFileDialog1.FileName);
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            pictureBox1.Image = image1;
            pictureBox1.BackgroundImage = image1;



        }

    }
}

当我再次运行应用程序时,我想在图片框中显示上次上载的图像

,然后您需要保存位置,并在应用程序启动时再次加载它

解决方案资源管理器
中,打开
属性
窗口并打开
设置
选项卡。创建一个名为LastImage的字符串

从“代码”中,您可以保存它:

Properties.Settings.Default.LastImage = openFileDialog1.FileName;
Properties.Settings.Default.Save();
并在打开时重新阅读:

string myImage = Properties.Settings.Default.LastImage;
if (File.Exists(myImage))
{
  pictureBox1.Image = Image.FromFile(myImage);
  //etc...
}

然后,您需要保存该位置,并在应用程序启动时再次加载它

解决方案资源管理器
中,打开
属性
窗口并打开
设置
选项卡。创建一个名为LastImage的字符串

从“代码”中,您可以保存它:

Properties.Settings.Default.LastImage = openFileDialog1.FileName;
Properties.Settings.Default.Save();
并在打开时重新阅读:

string myImage = Properties.Settings.Default.LastImage;
if (File.Exists(myImage))
{
  pictureBox1.Image = Image.FromFile(myImage);
  //etc...
}

哦,好的,但是我找不到properties.settings.lastimage,它正在显示properties.setttings.default,就像这样..很抱歉。。我仍然找不到这个…Properties.Settings.Default.LastImage(.LastImage)。。本文介绍如何将属性/设置添加到项目中。您可以在以后使用它们,正如LarsTech已经很好地解释的那样。@user903550您必须首先在“解决方案资源管理器”中打开“属性”,然后选择“设置”选项卡。创建字符串变量“LastImage”并保存解决方案。它将在代码中对您可用。哦,好的,但我找不到properties.settings.lastimage,它显示的是properties.setttings.default,如下所示..很抱歉。。我仍然找不到这个…Properties.Settings.Default.LastImage(.LastImage)。。本文介绍如何将属性/设置添加到项目中。您可以在以后使用它们,正如LarsTech已经很好地解释的那样。@user903550您必须首先在“解决方案资源管理器”中打开“属性”,然后选择“设置”选项卡。创建字符串变量“LastImage”并保存解决方案。然后,它将在代码中对您可用。