//browse and set image private void btnBrowseScreenshot_Click(object sender, EventArgs e) { var fd = new OpenFileDialog(); fd.Filter = "PNG(*.png)|*.png;|Bmp(*.bmp)|bmp;|Jpeg(*.jpg)|*.jpg"; fd.AddExtension = true; if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { long length = new System.IO.FileInfo(fd.FileName).Length; if (length >= 2000000) { MessageBox.Show("Image is Too Large, Only select file below 2MB", "Invalid Image", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if ( !String.Equals(Path.GetExtension(fd.FileName), ".png", StringComparison.OrdinalIgnoreCase) && !String.Equals(Path.GetExtension(fd.FileName), ".bmp", StringComparison.OrdinalIgnoreCase) && !String.Equals(Path.GetExtension(fd.FileName), ".jpg", StringComparison.OrdinalIgnoreCase) ) { MessageBox.Show("You must select an Image file.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { Debug.WriteLine(length); //Bitmap.FromFile(fd.FileName); Bitmap img = new Bitmap(fd.FileName); pbscreenshot.Image = img; this.Refresh(); bug.setImageLocation(fd.FileName); txtscreenshotlocation.Text = fd.FileName; } catch (Exception ex) { MessageBox.Show("Failed to Load Image:" + "\n" + ex.Message, "Load Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); // failed to load, display error message } } }