Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this on my MDI form:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FTEMPC_SalesAndInventory
{
    public partial class mdiMain : Form
    {

        frmLogin frm = new frmLogin();
        public mdiMain()
        {
            InitializeComponent();
        }

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

        private void dashboardToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmAdmin_Module frm = new frmAdmin_Module();
            frm.Show();
            frm.MdiParent = this;
        }
        private void clickToolStripMenuItem(object sender, EventArgs e)
        {
            ToolStripMenuItem tool = sender as ToolStripMenuItem;
            new disableAdminMenus().callForms(this, tool);

        }
        private void mdiMain_Load(object sender, EventArgs e)
        {
//hide menubar first for login
            mStrip_mdi.Visible = false;

            WindowState = FormWindowState.Maximized;
//show login window
            frm.Show();
            frm.MdiParent = this;

//after successful login
            if (frm.emp_designation.Equals("Sales"))
            {
                ToolStripMenuItem[] tools = { viewToolStripMenuItem, manageToolStripMenuItem, dashboardToolStripMenuItem };
                new disableAdminMenus().disableAdminMenuItems(tools);

                frmClerk_Main frm = new frmClerk_Main();
                frm.Show();
                frm.MdiParent = this;
            }
            else if (frm.emp_designation.Equals("Inventory"))
            {

                manageToolStripMenuItem.Visible = true;
                purchaseOrdersToolStripMenuItem.Visible = true;
                categoryUnitToolStripMenuItem.Visible = true;

                companyInformationToolStripMenuItem.Visible = false;
                supplierInformationToolStripMenuItem.Visible = false;
                employeeInformationToolStripMenuItem1.Visible = false;
                backupRestoreToolStripMenuItem.Visible = false;

                frmProductManagement frmprod = new frmProductManagement();
                frmprod.Show();
                frmprod.MdiParent = this;

            }
            else if (frm.emp_position.Equals("Admin"))
            {
                ToolStripMenuItem[] tools = { viewToolStripMenuItem, manageToolStripMenuItem, dashboardToolStripMenuItem };
                new disableAdminMenus().enableAdminMenuItems(tools);
                frmAdmin_Module frmadmin = new frmAdmin_Module();
                frmadmin.Show();
                frmadmin.MdiParent = this;
            }
        }

        private void logOutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult dialog = MessageBox.Show("Are you sure you want to log out?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dialog == DialogResult.Yes)
            {
                string date = DateTime.Now.ToString("MM/dd/yyyy");
                string time = DateTime.Now.ToString("h:mm:ss tt");
                string action = "Logged out.";
                OO_Methods.audit_trans(time, date, action, new frmLogin().au_uname);
                new frmLogin().Show();
                this.Hide();
            }
        }

        private void exitToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            DialogResult dialog2 = MessageBox.Show("Are you sure you want to exit the application?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dialog2 == DialogResult.Yes)
            {
                string date = DateTime.Now.ToString("MM/dd/yyyy");
                string time = DateTime.Now.ToString("h:mm:ss tt");
                string action = "System Exit";
                OO_Methods.audit_trans(time, date, action, new frmLogin().au_uname);
                Application.Exit();
            }
        }

        private void reportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmReport_FINAL frm = new frmReport_FINAL();
            frm.Show();
            frm.Parent = this;
        }

        private void auditTrailToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            frmAuditTrail_FINAL frm = new frmAuditTrail_FINAL();
            frm.Show();
            frm.Parent = this;
        }

        private void mStrip_mdi_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }
    }
}



The login form opens within the MDI. But after a successful login, how will I show the next form? It depends on the login credentials of the user which form will be shown. if admin, admin module. if sales, transaction. if inventory, product management module. Which are inside the if-else statement.

What I have tried:

I have tried adding
this.Hide();
to my login form after the messagebox that says the login is successful. The frmlogin becomes hidden but the next form doesn't show up.
Posted
Updated 3-Oct-16 0:59am
v2

1 solution

Have you tried setting mdi parent before calling show as per MSDN?


Creating MDI Child Forms[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900