Skip to content

Opening a dialog after closing an OpenFileDialog #46

@axx0

Description

@axx0

So, I wish to:

  1. Open an OpenFileDialog
  2. After closing the OpenFileDialog immediately open another custom dialog

Here is my code:

using Modern.Forms;
using System.Drawing;

namespace ModernFormsApp1
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            this.Shown += async (_, _) =>
            {
                var ofd1 = new OpenFileDialog
                {
                    Title = "Open this file 1"
                };
                await ofd1.ShowDialog(this);

                await new DialogForm().ShowDialog(this);
            };
        }
    }

    public class DialogForm : Form
    {
        public DialogForm()
        {
            Text = "Dialog Form";
            Size = new Size(500, 250);

            var button3 = Controls.Add(new Button
            {
                Text = "DialogResult.Abort button",
                Left = 10,
                Top = 124,
                Width = 250,
                DialogResult = DialogResult.Abort
            });

            var button4 = Controls.Add(new Button
            {
                Text = "DialogResult.None button",
                Left = 10,
                Top = 164,
                Width = 250,
                DialogResult = DialogResult.None
            });
        }
    }
}

When I run the code the OpenFileDialog is opened, but when I close it I get a blank dialog screen:
image

However when I change the order of dialogs (first opening the custom dialog and then the OpenFileDialog) it runs ok.

What am I doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions