For opening FileDialog You must need to store the return value of ShowDialog() in a variable and then compare this to DialogResult.OK.
I wrote it as a note to myself for future use.
C# Code:
1 2 3 4 5 6 7 8 | var result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK){ string path = openFileDialog1.FileName; ExtractIcon(path); } |
Alternative:
1 2 3 4 5 6 7 | if (openFileDialog1.ShowDialog() == DialogResult.OK) { string path = openFileDialog1.FileName; ExtractIcon(path); } |
Open Image File:
1 2 3 4 5 6 7 8 9 10 11 12 | string sFile; OpenFileDialog openFileDialog1 = new OpenFileDialog(); PictureBox pBox = new PictureBox(); openFileDialog1.Filter = "Image File (*.jpg;*.bmp;*.gif)|*.jpg;*.bmp;*.gif"; if(openFileDialog1.ShowDialog() == DialogResult.OK) { sFile = openFileDialog1.FileName; pBox.Image = System.Drawing.Bitmap.FromFile(sFile); pBox.SizeMode = PictureBoxSizeMode.StretchImage; } |