Displaying image on a Panel
this i a snippet of my code....
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开发者_如何学Go.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");
}
}
The question is: Am i able to display my image browsed on a Panel instead of a PictureBox ?
You could set the BackGroundImage of the panel to the image.
panel.BackgroundImage = Image.FromFile(open.FileName);
Should do the trick.
Basically PictureBox is made to display images while Panel is for drawing in it(curves, lines, rectangles,....)
So I suggest better to use pictureBox, but if you want to show image in panel.
- You can draw it
on paintevent
OR - Use
BackgroundImageproperty.
Yes. The Panel class has a member called BackImageUrl. Just specify the URL of the picture you want to use as the background.
For winforms, you can use the BackgroundImage and BackgroundImageLayout properties of the Panel.
加载中,请稍侯......
精彩评论