Note that there are some explanatory texts on larger screens.

plurals
  1. POC# OpenFileDialog not opening file
    primarykey
    data
    text
    <p>I'm trying to use openFileDialog to open a Bitmap image and place it on my form. My form construtor...</p> <pre><code> public Form1() { InitializeComponent(); drawing = new Bitmap(drawingPanel.Width, drawingPanel.Height, drawingPanel.CreateGraphics()); Graphics.FromImage(drawing).Clear(Color.White); // set default value for line thickness tbThickness.Text = "5"; } </code></pre> <p>... opens a new form with a blank screen, and I can draw on it using the mouse and various color selector buttons. I then save the file with this method:</p> <pre><code>private void btnSave_Click(object sender, EventArgs e) { // save drawing if (file == null) // file is a FileInfo object that I want to use // to check to see if the file already exists // I haven't worked that out yet { drawing.Save("test.bmp"); //SaveBitmap saveForm = new SaveBitmap(); //saveForm.Show(); } else { drawing.Save(fi.FullName); } } </code></pre> <p>The image does save to the debug folder as a .bmp file. Then I use OpenFileDialog to open the file:</p> <pre><code>private void btnOpen_Click(object sender, EventArgs e) { FileStream myStream; OpenFileDialog openFile = new OpenFileDialog(); openFile.Filter = "bmp files (*.bmp)|*.bmp"; if (openFile.ShowDialog() == DialogResult.OK) { try { if ((myStream = (FileStream)openFile.OpenFile()) != null) { using (myStream) { PictureBox picBox = new PictureBox(); picBox.Location = drawingPanel.Location; picBox.Size = drawingPanel.Size; picBox.Image = new Bitmap(openFile.FileName); this.Controls.Add(picBox); } } } catch (Exception ex) { } } } </code></pre> <p>What happes is that OpenFileDialog box comes up. When I select the file test.bmp, the screen goes away and then reappears, when I select it again, the OpenFileDialog window goes away and I'm back to my form with no image. Was hoping for some pointers. No compile or runtime errors.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload