C#将图像添加到标签 [英] C# Adding Image to a Label

查看:80
本文介绍了C#将图像添加到标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我必须使用Visual C#2010开发WindowsForm,我需要做的是在标签上使它们成为图像. 我将图像包含在名为"images"的文件夹中的project/bin/Debug/中

Now i have to developing a WindowsForm using Visual C# 2010, What I need to be able to do is on a label make their be an image. I have got the images included in the project/bin/Debug/ in a folder named "images"

Image img = Image.FromFile("PR001.jpg");
Label lblImage = new Label();
lblImage.Parent = this;
lblImage.Image = img;
lblImage.Size = new Size(img.Width, img.Height);

我只需要带有扩展名(* .jpg)的文件

i need only file with extension (*.jpg)

有人可以帮助我吗?

推荐答案

由于您的图片位于图片"文件夹中,因此您必须修改此行

Since your images are in the "images" folder, you have to modify this line

Image img = Image.FromFile("PR001.jpg");

Image img = Image.FromFile("images/PR001.jpg");

注意:原始行将搜索程序可执行文件(.exe)所在的"debug"文件夹中的文件.

Note: The original line would search the file in "debug" folder, where your program executable (.exe) file is located.

这篇关于C#将图像添加到标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆