Setting PictureBox.Image property

Posted on 2005-04-29
Last Modified: 2009-07-29

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?


Question by:tr309

    Author Comment

    I forgot to mention that this is in .Net Compact Framework as I'm developing for PocketPC2003.
    LVL 6

    Accepted Solution

    try this

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

    intellisense sometimes doesn't work

    Author Comment

    It says System.Drawing.Image does not contain a definition for FromFile.

    What's up with this?

    Author Comment

    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,

    LVL 6

    Expert Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    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.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now