[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Setting PictureBox.Image property

Posted on 2005-04-29
5
Medium Priority
?
295 Views
Last Modified: 2009-07-29
Hi,

I have a PictureBox control on my form and I'm having difficulty setting its Image property at run-time. I was trying this:

imgDisplay.Image = System.Drawing.Image ...

expecting Intellisense to give me the FromFile() method, but I can't seem to access any of the Image methods.

I was hoping to supply a string containing the filename to this method.

Can anyone help?

Thanks,

Rich
0
Comment
Question by:tr309
  • 3
  • 2
5 Comments
 

Author Comment

by:tr309
ID: 13894068
I forgot to mention that this is in .Net Compact Framework as I'm developing for PocketPC2003.
0
 
LVL 6

Accepted Solution

by:
zupi5 earned 100 total points
ID: 13894093
try this

imgDisplay.Image = System.Drawing.Image.FromFile(@"c:\blah.jpg");

intellisense sometimes doesn't work
0
 

Author Comment

by:tr309
ID: 13894158
It says System.Drawing.Image does not contain a definition for FromFile.

What's up with this?
0
 

Author Comment

by:tr309
ID: 13894543
Oh well. I think I've found the solution. Contrary to descriptions provided by numerous online sources (including MSDN) - the way to set the Image property of a PictureBox at run-time is by using the System.Drawing.Bitmap class:

Bitmap test = new Bitmap(@"\Temp\test.jpg");
pictureBox1.Image = test;

At least, this worked for me.

Never mind.

Thanks anyway,

Rich
0
 
LVL 6

Expert Comment

by:zupi5
ID: 13895314
oh you are using compact framework, did not see that post while writing my response. :NET compact framework Image object does not support FromFile function, you'll have to doit with the bitmap.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month18 days, 20 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question