The application of the first alignment path in Picturebox in C #

Source: Internet
Author: User

Objective

Recent projects need to PictureBox display network pictures of the small function to complete, do not want to use absolute path to take pictures of local files, because in the future to release to the user's own configuration will be very troublesome, simply set the path to a relative path, the picture is placed in their own projects. So the question is, how do you use PictureBox to take out the pictures you want to show based on the relative path?

The most commonly used relative path for C # is to find the path you are looking for, starting with the path that is currently on the current program, which is the following two simplest ways:

1. Program root directory. (i.e. the path where the EXE program resides)
// The following two paths are equivalent, and are all you.jpg pictures under the Internet folder where the EXE program is located (usually bin\debug\) string @" . \internet\you.jpg "  string@ "internet\you.jpg"
2. Parent directory:
string @" .. \internet\you.jpg"// the you.jpg picture under the Internet folder of the root directory of the program's parent directory (usually bin\) string @" .. \..  \internet\you.jpg"; // The you.jpg picture under the Internet folder of the top level two directory (usually program name \) of the program root directory
3. PictureBox take out the corresponding picture

I put it under the bin\debug, all using the method of the first relative path.

    Picinternet.image = Image.FromFile (@ ". \internet\you.jpg");

Display the picture successfully.

4. By the way, make note of the Picturebox control's tips 4.1 making the loaded picture self-using the control size

Set the PictureBox control separately Backgroundimagelayout=stretch,sizemode=stretchimage

4.2 Make PictureBox Transparent

The BackColor property of the PictureBox is set to Color.transparent

The application of the first alignment path in Picturebox in C #

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.