问题
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