How to stop two forms to open simultaneously

Experts
I have a question .
As you can see that in the attached image as I click the submenu Sales Entries then that form is opening but after that if I click the Dealer Entries then this form goes behind the Sales Entries.

Similarly if at first I click the Dealer Entries then that form opens but as I click the Sales Entries form then the Sales Entries form goes below the Dealer Entries form.

But this is not expected.
My question is that how to prevent one form to get opened unless another form is not closed.

For your information I would like to tell you that I have used here Dealer Entries form and Sales Entries form these are border less form and the code I used is as


  private void salesEntriesToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            FormSalesEntry fse = new FormSalesEntry();
            fse.TopLevel = false;
            WorkingPanel.Controls.Add(fse);
            fse.Visible = true;
           

        }

        private void dealerEntriesToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Form_DealerInfo fdi = new Form_DealerInfo();
            fdi.TopLevel = false;
            WorkingPanel.Controls.Add(fdi);
            fdi.Visible = true;
        }
My question is  
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 CDManagementSoftware
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void salesEntriesToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void salesEntriesToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            FormSalesEntry fse = new FormSalesEntry();
            fse.TopLevel = false;
            WorkingPanel.Controls.Add(fse);
            fse.Visible = true;
            

        }

        private void dealerEntriesToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Form_DealerInfo fdi = new Form_DealerInfo();
            fdi.TopLevel = false;
            WorkingPanel.Controls.Add(fdi);
            fdi.Visible = true;
        }
    }
}

Open in new window

error.JPG
ANINDYAAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SriVaddadiCommented:
IOW,  you want to make the form as modal. does it sound right?  Use ShowDialog method of the form instead of setting visible property

you could do something like this

FormSalesEntry fse = new FormSalesEntry();
            fse.TopLevel = false;
            WorkingPanel.Controls.Add(fse);
fse.ShowDialog(this);



0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
(not sure you can use ShowDialog() when the form is not TopLevel and is being displayed in a Panel...haven't tried it)

You could either:
(1) Check the WorkingPanel to see if it already has a form loaded:
    if (!WorkingPanel.Controls.Count == 0)
    {
       // load the new form up, the above check may need to be more complex depending on what is in WorkingPanel
    }
(2) Disable the menu option until the form is closed by subscribing to the FormClosed() event and re-enabling when the menu when it fires.
0
ANINDYAAuthor Commented:
Expert SriVaddadi
Thanks for your suggestion but sir it not working sir.
I tried.
It is showing error.
Thanking you
error.JPG
0
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

ANINDYAAuthor Commented:
Expert Idle_Mind
I hope you can remember me.Sir it is your code only sir as you had suggested me that I am using in the total project.
I am extremely elated to see the result.
But I am facing a problem as I depicted in this question .
As you can see there are
Sales entries ,dealer entries,inventory,customer,payment entries. So what is happening is all the forms are piled on another.
Sir it is nice to see you only again .
I did not know how to contact to you.
Sir I can not disable the menu option as otherwise  the customer will not be able to understand  them..The end user might think those are options for me or I am unable to use them..

Sir your 1st option I tried but it is becoming too heavy for me to control the code.
Can you suggest a simple option.sir.
Thanking you Idle_Mind for answer ,
Anindya Chatterjee
Bangalore
India


0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
How are you closing the forms?

As I said before, you can simply prevent the opening of another form if there is already one open in the panel:

        private void salesEntriesToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (WorkingPanel.Controls.Count == 0)
            {
                FormSalesEntry fse = new FormSalesEntry();
                fse.TopLevel = false;
                WorkingPanel.Controls.Add(fse);
                fse.Visible = true;
            }
        }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ANINDYAAuthor Commented:
Again Thanks Idle_Mind for your timely answer.
I am sorry for not responding in time as I was not in good health.
Thanking you
Anindya Chatterjee
Bangalore
India
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.