Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to be able to use picturebox in windows but don't know how to do it. I am new to programming( Been doing it for 5 days now). I made a picturebox as a first project(WooHoo!)and would like to demonstrate my creation to my wife. It's not much, but I'm proud of it. I've tried to do it on my own but have hit a wall. Can you help? I can view the picturebox in windows, but I can't load any pictures on it like I can when I Debug in C#. Please understand, I am not technical in any way. But since Retiring, it is either learn a new skill, or go crazy.

When I Debug the code in C#, I can load a picture on it from "pictures" in My Library. When I bring the picturebox up in "Documents", I can view the picturebox, but I can't put any pictures on it. All I can do is push the buttons on the picturebox.
Posted
Updated 12-Jul-12 6:26am
v5
Comments
Sandeep Mewara 12-Jul-12 11:26am    
You need to elaborate more on what are you trying to do and where are you stuck. For now, we have no clue on what kind of help you are expecting and wahts troubling you.

Use Improve Question link and update your question with more details.
Sander Rossel 12-Jul-12 11:49am    
What do you mean? A PictureBox is a simple, standard, .NET WinForms Control (http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.aspx)... Anyone could drag one onto a Form and set its picture. It's not something you should 'make' yourself.

If you really did make one yourself we will need to see a bit of code to see what you've done and where you could possibly have gone wrong.
[no name] 12-Jul-12 12:04pm    
I appreciate that you are just learning but "I can view the picturebox in windows, but I can't load any pictures on it like I can when I Debug in C#" makes no sense. Can you elaborate on what exactly you are trying to do?

1 solution

Picture boxes are pretty simple when you get the hang of them - the important properties for you are Image and SizeMode.
The first of these determines which picture will be displayed, and the second says how it it shown.

Going backwards, set the SizeMode to StretchImage - you can do this in the designer via the Properties pane, or in code by:
myPictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
StrechImage mode means that the picture will be re-sized to fit in the PictureBox.

Now, set the Image. Again, you can do this in the designer, via the properties pane, or in code:
myPictureBox.Image = Image.FromFile(@"D:\Temp\MyPic.jpg");
Where the bit in the double quotes is the full path and name of the file. The '@' at the start just says "turn off special character processing" and lets you type the path with single backslash characters.

Run it! It should display the image from the file in your PictureBox control.

[edit]Typos. Lots of the buggers. - OriginalGriff[/edit]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900