class MyApplicationContext : ApplicationContext
{
public MyApplicationContext()
{
new frmLogin().Show();
}
}
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
//防止程序多次运行多进行相关判断取值
string mName = Process.GetCurrentProcess().MainModule.ModuleName;//获取主模块的Name
string pName = Path.GetFileNameWithoutExtension(mName);//获取该主模块运行的路径不带后缀
Process[] myProcess = Process.GetProcessesByName(pName);
if (myProcess.Length > 1)
return;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MyApplicationContext());
}
}
public partial class frmLogin : Form
{
public frmLogin()
{
InitializeComponent();
}
AdminInfo admin = null;
//登陆
private void btnLogin_Click(object sender, EventArgs e)
{
if (txtName.Text.Length == 0)
{
MessageBox.Show("帐号不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (txtPass.Text.Length == 0)
{
MessageBox.Show("密码不能问空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
//获取数据库里的数据
admin = Admin.GetAAdminInfo(txtName.Text, txtPass.Text)[0];
}
catch { }
if (admin == null)
{
MessageBox.Show("帐户或密码不正确!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
frmMain frm = new frmMain(admin);
frm.Show(); //就是在这一句代码上出错
this.Dispose();
}
{
public MyApplicationContext()
{
new frmLogin().Show();
}
}
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
//防止程序多次运行多进行相关判断取值
string mName = Process.GetCurrentProcess().MainModule.ModuleName;//获取主模块的Name
string pName = Path.GetFileNameWithoutExtension(mName);//获取该主模块运行的路径不带后缀
Process[] myProcess = Process.GetProcessesByName(pName);
if (myProcess.Length > 1)
return;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MyApplicationContext());
}
}
public partial class frmLogin : Form
{
public frmLogin()
{
InitializeComponent();
}
AdminInfo admin = null;
//登陆
private void btnLogin_Click(object sender, EventArgs e)
{
if (txtName.Text.Length == 0)
{
MessageBox.Show("帐号不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (txtPass.Text.Length == 0)
{
MessageBox.Show("密码不能问空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
//获取数据库里的数据
admin = Admin.GetAAdminInfo(txtName.Text, txtPass.Text)[0];
}
catch { }
if (admin == null)
{
MessageBox.Show("帐户或密码不正确!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
frmMain frm = new frmMain(admin);
frm.Show(); //就是在这一句代码上出错
this.Dispose();
}
而你现在的程序好像是先有frmLogin 窗体再有frmMain。
改成Close()看看~frmMain 写个AdminInfo类型的属性,复值进去,不要给构造函数传参数。
{
public MyApplicationContext()
{
new frmLogin().Show();
}
}
不知道是不是跟这个有联系! 这个是我网上找来的! 就是要来实现show主窗体的时候可以直接把frmLogin的窗体释放关闭! 不用这个方法我不知道还有什么方法把frmLogin关闭掉!