2010-12-12 15 views
4

に画像を表示させる。この私に私のコードのスニペット....パネル

public void btn_browse_Click_Click(object sender, EventArgs e) 
    { 

     try 
     { 
      OpenFileDialog open = new OpenFileDialog(); 
      open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp"; 
      if (open.ShowDialog() == DialogResult.OK) 
      { 
       scan.Enabled = true; 
       pic = new Bitmap(Width, Height, PixelFormat.Format24bppRgb); 
       pic2 = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);         

       pic = new Bitmap(open.FileName); 
       pic2 = new Bitmap(open.FileName); 

       pictureBox1.Image = pic; 
       pictureBox2.Image = pic2; 
       pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; 
       textBox1.Text = open.FileName; 
       pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; 



      } // end of if opendialog 


     } // end of try 

     catch (Exception) 
     { 
      throw new ApplicationException("Failed loading image"); 
     } 


    } 

ある質問:私は私の画像を表示することができアムではなく、ピクチャのパネルで閲覧?

答えて

9

パネルのBackGroundImageをイメージに設定できます。
panel.BackgroundImage = Image.FromFile(open.FileName);
このトリックを行う必要があります。

0

はい。 Panel classにはBackImageUrlというメンバーがあります。背景として使用する画像のURLを指定するだけです。

3

は基本的にPictureBox画像を表示するために行われる(曲線、直線、四角形、....)

だから私は、ピクチャボックスを使用する方をお勧め、しかし、あなたがパネルに画像を表示したい場合。

  1. あなたはBackgroundImageプロパティを使用して、それをon paintイベント
    OR
  2. を描くことができます。