Need Advice - Using images with C# WinForms VS.NET Project

.NET programming topics
Post Reply
Neofriend
Captain
Captain
Posts: 103
Joined: Wed Dec 23, 2009 3:37 pm
Location: Pakistan

Need Advice - Using images with C# WinForms VS.NET Project

Post by Neofriend » Tue Jan 05, 2010 4:35 pm

I made the first form, and it has the background and a couple of small images placed on the form. Made the second form and so on. Am having a couple of forms by now, just the GUI so far.

Now this questions arises from a bad experience I had in Java. I saved all of my images in a folder somewhere at PC and referenced the images from there. Later, I deleted that image folder and thought the images would still be okay in the project. But it was all empty in the project.

In VS.NET here, how should I use images? Where should I place them? Inside the project? And should I use resources to manage the images or how exactly? Some explanation would be really helpful as am just starting off.

So that I am sure where ever I move the project and whatever I do, i won't lose the images inside the project.

For now I've made a folder namely images, inside the project and directly referencing it.

Thank you.
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: Need Advice - Using images with C# WinForms VS.NET Project

Post by Neo » Tue Jan 05, 2010 5:27 pm

Easy way to do this is to add a PictureBox and load the image from property Image.
After loading it to PictureBox you don't need to keep the file on disk (It is stored to application).
And you may make this PictureBox invisible and use the loaded image anywhere in the project.

There are so much of other ways to do the same thing. Just chose the easiest for you.
Neofriend
Captain
Captain
Posts: 103
Joined: Wed Dec 23, 2009 3:37 pm
Location: Pakistan

Re: Need Advice - Using images with C# WinForms VS.NET Project

Post by Neofriend » Tue Jan 05, 2010 11:30 pm

Sounds nice. I've already been using pictureBox for small pictures needed on the form which are clickable.

Can I use pictureBox for loading an image, disabling the pictureBox and using the same picture as Background of the form?

Or what other way of using background image is the easiest?
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: Need Advice - Using images with C# WinForms VS.NET Project

Post by Neo » Wed Jan 06, 2010 12:12 am

Simple as follows.

Code: Select all

Form1.ActiveForm.BackgroundImage = pictureBox1.Image;
However my point is, when you load an image to BackgroundImage property of Form using the property window, even you delete the image from disk it persist with the From. However you will have to exit from VS.net to delete the image from disk.
Post Reply

Return to “.NET Programming”