点击图片名,让图片在pictureBox中显示 z

  public string filepath;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "*.gif|*.jpg";
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string  path = this.openFileDialog1.FileName;
                 filepath=Path.GetDirectoryName(path); 
                FileInfo f = new FileInfo(path);
                this.listBox1.Items.Add(f.Name);
            }
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            pictureBox1.Image = Image.FromFile(filepath + "\\" + listBox1.SelectedItem.ToString());
        }

 

你可能感兴趣的:(图片)