C# Adding Image to a Label

橙三吉。 提交于 2019-12-25 12:55:12

问题


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);

i need only file with extension (*.jpg)

can someone help me ?


回答1:


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.




回答2:


You should take a look at the Label.BackgroundImage property.

And this links describes what you are looking for:

http://www.c-sharpcorner.com/uploadfile/mahesh/label-in-C-Sharp/

http://www.java2s.com/Tutorial/CSharp/0460__GUI-Windows-Forms/AddimagetoLabel.htm



来源:https://stackoverflow.com/questions/23891155/c-sharp-adding-image-to-a-label

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!