I have windows application, where my program have the following code:
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
Now, on the MainForm(), I have few buttons, where upon clicking each of the button, I hide the MainForm and open a new form (Windows Form) using opendialog as shown in the below code:
this.Hide();
TestCenter testCenter = new TestCenter();
testCenter.ShowDialog();
this.Show();
Now, in the TestCenter form, I have a functionality (OpenFileDialog) for selecting a file, as shown in the below code:
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "image file |*.jpg;*.png;*.gif";
DialogResult dr = ofd.ShowDialog();
if (dr == DialogResult.Cancel)
return;
pictureBox_PartImage.Image = Image.FromFile(ofd.FileName);
txt_ImagePath.Text = ofd.FileName;
I have a TextBox and a PictureBox, for showing the filepath and the image after making the selection in OpenFileDialog.
The weird thing is, that, when I run this program from Visual Studio or from the installed programs on my laptop (Windows 10) it is working excellently without any issue. But when I install this on client machine (Windows 7) it is freezing this Windows Form application when I click on the button which calls this OpenFileDialog().
Can someone please help me with this issue?
--------EDIT--------2/7/18--------
private void btnImage_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
// ofd.ShowHelp = true;
ofd.Filter = "Image Files (*.png, *.gif, *.jpg)|*.png; *.gif*;*.jpg";
DialogResult dr = ofd.ShowDialog();
if (dr == DialogResult.Cancel)
return;
pictureBox_PartImage.Image = Image.FromFile(ofd.FileName);
txt_ImagePath.Text = ofd.FileName;
}