1
Answer

User Control

Paul Loughridge

Paul Loughridge

16y
1.9k
1

I have a User Control which has a PictureBox with an Image Property.
When the control is placed on the MainForm it no longer has an Image Property. The MainForm has an openFileDialog control.

The code:

 private void OpenImage()
  {
   try
   {
    this.openFileDialog1.ShowDialog();
                openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";

    string path = this.openFileDialog1.FileName;
    this.viewer1.Image = Image.FromFile(path);
   }
   catch
   {
                MessageBox.Show ("Invalid selection. Must be an image file", "Picture Viewer", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
            }
  }

Answers (1)