Hi Guys
Can you please take a look at following app to see what I am doing wrong?

Download App(WinFormsStarts)

What I want to do is running multiple modal forms AND keeping the MainApp form accessible until finishing all required modals.As you can see from the application, as soon as you run the program the MainApp form (in Maximized windows State) and the Welcome form pops up.
till here everything is fine but when I chose the "Start New Project" the QuickStart form pops up BUT the MainApp minimize which is not meant to be.
This issue also happen when user chose the "Start Existing Project" then the MainApp minimize again and the Open dialog appear on the screen.

Here are the codes ,as well:
1- MainApp

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WinFormStarts
{
    public partial class MainApp : Form
    {
        public MainApp()
        {
            InitializeComponent();
        }

        private void MainApp_Load(object sender, EventArgs e)
        {
            Welcome welcomeForm = new Welcome();
            welcomeForm.ShowDialog();
        }
    }
}

2- Welcome Form

using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WinFormStarts
{
    public partial class Welcome : Form
    {
        public Welcome()
        {
            InitializeComponent();
        }

         private void btnExisting_Click(object sender, EventArgs e)
        {
            this.Hide();
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.ShowDialog();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
            Application.Exit();
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            this.Hide();
            QuickStart qs = new QuickStart();
            qs.ShowDialog();
        }
    }
}

3- QuickStart Form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WinFormStarts
{
    public partial class QuickStart : Form
    {
        public QuickStart()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
            Application.Exit();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

Please let me know what is wrong with this apss. Thanks for your time in advanced

Recommended Answers

All 3 Replies

Change

welcomeForm.ShowDialog();

To

welcomeForm.Show();

Yep, ShowDialog() will make the form to be TopMost all the time when opened.
While Open it only puts the form on top of all when opened, and if you click some other form, this one will be hidden bellow newly clicked form.

Hi mazzica1 and Mitja,
Thanks for your time and comments.Well, I did'nt want to use the Show() method since I need to create a modal form here.
However, I find the solution and it is specifying owner for forms inside the ShowDialog()

For WelcomeForm form as:

WelcomeForm.ShowDialog(this);

and for the QuickStart as:

qs.ShowDialog(this.Owner);

Thanks again for your time

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.