Frage

Right now I have this code to open an image from an MDIParent Window called MDIParent1

private void OpenFile(object sender, EventArgs e)
{
    OpenFileDialog openFileDialog = new OpenFileDialog();
    openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
    openFileDialog.Filter = "Image Files (*.jpg)|*.jpg|All Files (*.*)|*.*";
    if (openFileDialog.ShowDialog(this) == DialogResult.OK)
    {
        string FileName = openFileDialog.FileName;
        Process.Start(@FileName);
    }
}

This opens a new window with my image fine however I want this to open as a child window to MDIParent1. Any help would be greatly appreciated. Thank You

War es hilfreich?

Lösung

Process.Start(@FileName); is the same like you double click the file from explorer. So it will open a new window. If you have set default program to open the image, then it will open the program instead.

If you want to do it by C#, create a form with a PictureBox in it. Then instead of calling Process.Start(@FileName);, call the form like this:

Form1 form = new Form1();
form.MdiParent = this;
form.PictureBox1.ImageLocation = FileName;
form.Open();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top