[英]C# Adding Image to a Label
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.现在我必须使用 Visual C# 2010 开发 WindowsForm,我需要能够做的是在标签上使它们成为图像。 I have got the images included in the project/bin/Debug/ in a folder named "images"
我已将项目/bin/Debug/ 中的图像包含在名为“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);
i need only file with extension (*.jpg)我只需要带扩展名的文件 (*.jpg)
can someone help me ?有人能帮我吗 ?
You should take a look at the Label.BackgroundImage property.您应该查看Label.BackgroundImage属性。
And this links describes what you are looking for:此链接描述了您要查找的内容:
http://www.c-sharpcorner.com/uploadfile/mahesh/label-in-C-Sharp/ http://www.c-sharpcorner.com/uploadfile/mahesh/label-in-C-Sharp/
http://www.java2s.com/Tutorial/CSharp/0460__GUI-Windows-Forms/AddimagetoLabel.htm http://www.java2s.com/Tutorial/CSharp/0460__GUI-Windows-Forms/AddimagetoLabel.htm
Since your images are in the "images" folder, you have to modify this line由于您的图像位于“图像”文件夹中,因此您必须修改此行
Image img = Image.FromFile("PR001.jpg");
to到
Image img = Image.FromFile("images/PR001.jpg");
Note: The original line would search the file in "debug" folder, where your program executable (.exe) file is located.注意:原始行将搜索“debug”文件夹中的文件,您的程序可执行文件 (.exe) 位于该文件夹中。
This works for me:这对我有用:
Label ilabel = new Label(); // create a label
Image i = Image.FromFile("image.png"); // read in image
ilabel.Size = new Size(i.Width, i.Height); //set label to correct size
ilabel.Image = i; // put image on label
this.Controls.Add(ilabel); // add label to container (a form, for instance)
https://stackoverflow.com/a/16888310/470868 https://stackoverflow.com/a/16888310/470868
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.