i have a problem. i want to load image file or rar/zip to my WPF. when i click button on my WPF to open file dialog, i got some errors.
this is my code to open file dialog.
private void button1_Click(object sender, EventArgs e)
{
try
{
op.Title = "Select a File";
op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
"JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
"Portable Network Graphic (*.png)|*.png"+
"Zip Files|*.zip;*.rar";
if (op.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = System.Drawing.Image.FromFile(op.FileName);
_path = op.FileName;
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
my question is how to show image if file format is .jpg / .png, and show rar icon or any icon if file format is .rar / .zip in picturebox.
İf I don't understand wrong, the solution for your question is like this code below;
Firstly, you should choose a general picture to show in the picturebox when a zip or rar file is chosen by user. Then place the chosen picture (ex: rar.jpg) under the app's **bin\debug** folder.
Then, use the codes below;
I hope, the code is ok for your question.