Solved

Selecting an Image

Posted on 2006-10-23
3
206 Views
Last Modified: 2010-04-16
Hi,
What is the easiest way to have a user click on a button and select an image from there C:\ to be put into a picture box or panel?

Thanks

Peter
0
Comment
Question by:schenkp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 17792823
Something like...

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Title = "Select an Image File";
            ofd.InitialDirectory = @"c:\";
            ofd.Filter = "Image Files|*.bmp;*.jpg";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    pictureBox1.Image = Image.FromFile(ofd.FileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ofd.FileName, "Error opening File");
                }
            }
        }
0
 

Author Comment

by:schenkp
ID: 17800232
Hi Idle Mind,
Do you know how to size the picture that the user is selecting so it fits within the picturebox?

Thanks

Peter
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 17800442
What version C#?

If C# 2005, set the SizeMode() property on the PictureBox accordingly.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

630 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