不是有个filename吗,那个是路径,用picturebox.image=

解决方案 »

  1.   

    OpenFileDialog dlg = new OpenFileDialog();
    dlg.ShowDialog();
    FileStream fs = new FileStream( dlg.FileName, FileMode.Open, FileAccess.Read);
    System.Drawing.Image img = System.Drawing.Image.FromStream(fs);
    pictureBox1.Image = img;
    fs.Close();
      

  2.   

    初始化:
    this.button1 = new System.Windows.Forms.Button();
    this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
    this.pictureBox1 = new System.Windows.Forms.PictureBox();
    this.openFileDialog1.DefaultExt = "jpg";
    this.openFileDialog1.Filter = "JPEG and GIF Images(*.jpg;*.gif)|*.jpg;*.gif";
    this.openFileDialog1.InitialDirectory = "c:\\";//自己定义
    this.openFileDialog1.RestoreDirectory = true;
    this.button1.Location = new System.Drawing.Point(24, 32);//自己定义
    this.button1.Name = "button1";
    this.button1.Size = new System.Drawing.Size(184, 32);
    this.button1.TabIndex = 0;
    this.button1.Text = "Show OpenFileDialog";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    this.pictureBox1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
    | System.Windows.Forms.AnchorStyles.Left) 
    | System.Windows.Forms.AnchorStyles.Right);
    this.pictureBox1.Location = new System.Drawing.Point(8, 0);//自己定义
    this.pictureBox1.Name = "pictureBox1";
    this.pictureBox1.Size = new System.Drawing.Size(264, 352);
    this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
    this.pictureBox1.TabIndex = 0;
    this.pictureBox1.TabStop = false;应用:
    private void button1_Click(object sender, System.EventArgs e)
    {
    System.Windows.Forms.DialogResult dr = openFileDialog1.ShowDialog();
    if (dr == System.Windows.Forms.DialogResult.OK) 
    pictureBox1.Image=Image.FromFile(openFileDialog1.FileName);
    }