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 #