(GO) WinForm PictureBox background Display picture

Source: Internet
Author: User

This article was reproduced from: http://blog.csdn.net/meizhiyun/article/details/8639002

1. Get Local program picture

Method One

Picturebox1.backgroundimage = Image.FromFile (@ "Resources\bg.gif");

Or

Picturebox1.backgroundimage = new System.Drawing.Bitmap (@ "Resources\bg.gif");

Note: The resources folder must be placed under the Bin\Debug folder, otherwise you will not be prompted to find the picture

Method Two

First, in the root directory, create a new folder named Resources, put the picture in the folder, and then double-click on the Resources.resx, in the upper left corner of the "Add resources"---> "Add Existing Files", select the new Resources folder of the picture

Picturebox1.backgroundimage = Properties.Resources.bg2;

Method Three

Use the Imglist control to add a picture to the images property of Imglist

Picturebox1.backgroundimage= Imgfirst.images[0];

The disadvantage of using this method is that you cannot find the picture by the name of the picture, only the digital ID, and once the previous picture is deleted in the imglist, the order of the subsequent pictures will change.

2. Get pictures from the network

  method one

image myimg = Image.fromstream (WebRequest.Create (" Http://www.cma.gov.cn/tqyb/img/city/54823.jpg "). GetResponse (). GetResponseStream ());
Picturebox1.backgroundimage = myimg;

Method two

picturebox1.load ("http://www.cma.gov.cn/tqyb/img/city/54823.jpg");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.