关闭登录表单并根据用户凭据打开表单

本文关键字:表单 用户 登录 | 更新日期: 2024-10-24 15:53:16

我有一个登录表单。成功登录后,根据凭据的不同,用户将被引导到不同的表单。例如:如果用户是管理员,则应该显示adminform,如果用户是storekeeper,则应显示storekeeper表单等。。。

我已经实现了登录表单,并相应地对其进行了重定向。但问题是我使用this.hide()来隐藏登录表单,如果我试图关闭storekeeper/admin/manager表单,应用程序将继续运行,因为登录表单正在隐藏。

同样在登录表单中,关闭按钮或X提示用户:

protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }

if (MessageBox.Show("Would you like to Quit the Application?", "Quit Application", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                base.Dispose(disposing);
            }
        else
        {
            txtUserName.Text = string.Empty;
            txtPassword.Text = string.Empty;
        }

}

我读过不同的文章,但它们都有登录后的主窗体,所以它在应用程序中被调用。登录后运行(new Mainform())。showdialog()…

希望得到一些指导。。

提前感谢

关闭登录表单并根据用户凭据打开表单

你能尝试使用这个吗:

System.Windows.Forms.Application.Exit()

这将终止您的应用程序,而不管隐藏的表单是什么。

MSDN