Forum guidelines
  • Home
  • »
  • C# Language
  • »
  • Working with picture box in C# windows application forms.
AuthorQuestion
Working with picture box in C# windows application forms.
Posted on: 26 Dec 2011
Hi to all.

I was working on an application in windows forms using C# in Microsoft visual studio.

I'm not new to windows programming but i am new in using the picture box.

My question may seem very dumb but i please if you can help me out.

My application is simple: It simply accepts 3 integer values and it determines if these values can sides of a triangle or not, plus it also deduces (if it is a triangle) the type i.e. equilateral, isosceles, scalene triangle. 

When the user enters the three integers, the user must press a button "Get Results" and after pressing this button, i made a picture box showing the type of triangle.
I used this code:

 pb1.Image = new Bitmap("C:\\scab.bmp");

But the problem is that if i remove the images from that location, it gives a run-time error! So what code should i use so that these images can be saved in the applet and if i use it on another PC it wont crush.

I know that these types of applications my have to include a "resources" folder with them but if possible how can i do so that this applet is a a single file and can be executed anywhere without having to carry the images around every time.

Thanks for you support... Hope i have a suitable answer ASAP!.

Best Regards & Happy Holidays to everyone
Manuel Portelli

AuthorReply
Roy S
  • 0
  • 0
accepted
Re: Working with picture box in C# windows application forms.
Posted on: 26 Dec 2011   Accepted Answer
You're working with Visual Studio, right? Then it's very easy to add the bitmap to your project, just go to the properties of your project, select the resources tab on the left. Then just drag the bitmap you want to use into there and it should be added to the resources.

Now you can access that bitmap by using:
pb1.Image = YourNamespace.Properties.Resources.BitmapName;
(replace the bolded parts with the appropriate substitute)

More info about this can be found here:
http://msdn.microsoft.com/en-us/library/7k989cfy%28v=vs.80%29.aspx

Re: Working with picture box in C# windows application forms.
Posted on: 26 Dec 2011  
Welcome to C# Corner.

I am sorry, but your question is confusing. Roy explained how you can load a bitmap into the PictureBox. You seem to need to do more but it is not clear what more. I think you are saying that you need to draw in the bitmap; such as draw a triangle. You also say you need to save the bitmap. Is that correct? I do not however understand "remove the images from that location". So if you need more help and if you can provide some clarification then we can help you better.

Thinking is a feeling; pleasant for some and unpleasant for others.
Re: Working with picture box in C# windows application forms.
Posted on: 27 Dec 2011  
thanks both of you for your concern regarding my question

Seems that Roy S gave me the correct answer i was looking for.

Regards and thanks for your help!
Manuel Portelli

Re: Working with picture box in C# windows application forms.
Posted on: 27 Dec 2011  
I was not sure what you were asking. I misunderstood "so that these images can be saved in the applet". My understanding was that you needed to save the updated bitmaps during execution.

Thinking is a feeling; pleasant for some and unpleasant for others.

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.