在面板上显示图像
这是我的代码片段...
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");
}
}
问题是:我是否能够显示在面板而不是 PictureBox 上浏览的图像?
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.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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以将面板的 BackGroundImage 设置为该图像。
<代码>
panel.BackgroundImage = Image.FromFile(open.FileName);
应该做到这一点。
You could set the BackGroundImage of the panel to the image.
panel.BackgroundImage = Image.FromFile(open.FileName);
Should do the trick.
基本上,
PictureBox
用于显示图像,而Panel
用于绘图 在里面(曲线,直线,矩形,......)所以我建议最好使用pictureBox,但是如果你想在面板中显示图像。
在paint
事件上绘制它或
BackgroundImage
属性。Basically
PictureBox
is made to display images whilePanel
is for drawing in it(curves, lines, rectangles,....)So I suggest better to use pictureBox, but if you want to show image in panel.
on paint
eventOR
BackgroundImage
property.是的。 Panel 类 有一个名为
BackImageUrl
。只需指定要用作背景的图片的 URL 即可。Yes. The Panel class has a member called
BackImageUrl
. Just specify the URL of the picture you want to use as the background.对于 winforms,您可以使用 BackgroundImage 和 BackgroundImageLayout 属性。
For winforms, you can use the BackgroundImage and BackgroundImageLayout properties of the Panel.