using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using BusinessRuler;namespace Interface { public partial class FrmLogin : Form { public FrmLogin() { InitializeComponent(); } private void btnExit_Click(object sender, EventArgs e) { Application.Exit(); } private void btnOK_Click(object sender, EventArgs e) { if (!Check()) { return; } if (BusinessRuler.User.Login(this.txtUserName.Text.Trim(), this.txtPassword.Text.Trim())) { if (this.chxSaveUserName.Checked) { BusinessRuler.ReaderWirteConfig.WriteToAppConfig("userName", this.txtUserName.Text.Trim()); } else { BusinessRuler.ReaderWirteConfig.WriteToAppConfig("userName", ""); } this.DialogResult = DialogResult.OK;
FrmMain frmMain = new FrmMain(this.txtUserName.Text); //保存登陆的用户名 frmMain.CurrentUser = this.txtUserName.Text.Trim(); BusinessRuler.User objUser = new User(); frmMain.SetMnuSystemManageVisible(objUser.IsAdmin(this.txtUserName.Text.Trim())); frmMain.ShowDialog(); this.Close();
FrmMain MyMainForm = new FrmMain(userName);
保留 Public FrmMain()
{
}
添加 Public FrmMain(string userName):this()
{
}
就可以了 。。
{
}
public FrmMain(string userName)
{
}
当你定义了 带参数的构造函数
public FrmMain(string userName)
之后,
那个无参构造函数就被系统取消了如果你需要用 FrmMain()
初始化的话
就必须定一个一个
public FrmMain()
无参构造函数
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BusinessRuler;namespace Interface
{
public partial class FrmLogin : Form
{
public FrmLogin()
{
InitializeComponent();
}
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
} private void btnOK_Click(object sender, EventArgs e)
{
if (!Check())
{
return;
}
if (BusinessRuler.User.Login(this.txtUserName.Text.Trim(), this.txtPassword.Text.Trim()))
{
if (this.chxSaveUserName.Checked)
{
BusinessRuler.ReaderWirteConfig.WriteToAppConfig("userName", this.txtUserName.Text.Trim());
}
else
{
BusinessRuler.ReaderWirteConfig.WriteToAppConfig("userName", "");
} this.DialogResult = DialogResult.OK;
FrmMain frmMain = new FrmMain(this.txtUserName.Text);
//保存登陆的用户名
frmMain.CurrentUser = this.txtUserName.Text.Trim();
BusinessRuler.User objUser = new User();
frmMain.SetMnuSystemManageVisible(objUser.IsAdmin(this.txtUserName.Text.Trim()));
frmMain.ShowDialog();
this.Close();
}
}
public bool Check()
{
if (this.txtUserName.Text.Trim().Length < 8)
{
this.lblPrompt.Text = "用户名限制在8-20位之间!";
this.txtUserName.Focus();
this.txtUserName.Select();
return false;
}
else if (this.txtPassword.Text.Trim().Length < 8)
{
this.lblPrompt.Text = "密码长度限制在8-20位之间!";
this.txtPassword.Focus();
this.txtPassword.Select();
return false;
}
return true;
} private void txtUserName_MouseEnter(object sender, EventArgs e)
{
this.lblPrompt.Text = "用户名长度8-20位之间";
} private void txtUserName_MouseLeave(object sender, EventArgs e)
{
this.lblPrompt.Text = string.Empty;
} private void txtPassword_MouseEnter(object sender, EventArgs e)
{
this.lblPrompt.Text = "登陆密码长度8-20位之间";
} private void txtPassword_MouseLeave(object sender, EventArgs e)
{
this.lblPrompt.Text = string.Empty;
} private void FrmLogin_Load(object sender, EventArgs e)
{ string userName = BusinessRuler.ReaderWirteConfig.GetValueByKey("userName");
this.txtUserName.Text = userName;
if (userName.Trim().Length == 0)
{
this.chxSaveUserName.Checked = false;
}
else
{
this.chxSaveUserName.Checked = true;
}
}
}
}这是我的登陆页面代码!
{
}就没问题了。