本帖最后由 rt26773661 于 2010-06-27 01:21:00 编辑

解决方案 »

  1.   

    string userName="aaa";
    FrmMain MyMainForm = new FrmMain(userName); 
      

  2.   

    你在FrmMain的CS文件
    保留  Public FrmMain()
         {
         }
    添加 Public FrmMain(string userName):this()
        {
         }
    就可以了 。。
      

  3.   

    public FrmMain()
    {
    }
    public FrmMain(string userName)
    {
    }
      

  4.   

    一个类 默认是有一个隐形无参构造函数的
    当你定义了 带参数的构造函数
    public FrmMain(string userName)
    之后,
    那个无参构造函数就被系统取消了如果你需要用 FrmMain()
    初始化的话 
    就必须定一个一个
    public FrmMain()
    无参构造函数
      

  5.   

    我本想利用Splasher.Show(typeof(frmSplash));用来作为弹出欢迎页面,但是按照这方法就直接进FrmMain 页面了。并没有出现弹出页面……请问这是怎么回事啊!
      

  6.   

    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();
                    
                }
            }
            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;
                }
            }
        }
    }这是我的登陆页面代码!
      

  7.   

    你的代码里都没有定义不带参数的构造函数。当然调用的时候出错啦。加个函数public  Public FrmMain()
    {
    }就没问题了。